diff --git a/src/expr.rs b/src/expr.rs index c337b68f4bfb..4fe97a2cb2bc 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2764,7 +2764,11 @@ pub fn rewrite_assign_rhs, R: Rewrite>( 0 }; // 1 = space between operator and rhs. - let orig_shape = shape.offset_left(last_line_width + 1)?; + let orig_shape = shape.offset_left(last_line_width + 1).unwrap_or(Shape { + width: 0, + offset: shape.offset + last_line_width + 1, + ..shape + }); let rhs = choose_rhs(context, ex, orig_shape, ex.rewrite(context, orig_shape))?; Some(lhs + &rhs) } diff --git a/src/items.rs b/src/items.rs index 90bea58ea1ba..bff5c00d2f47 100644 --- a/src/items.rs +++ b/src/items.rs @@ -945,7 +945,9 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds. if !type_param_bounds.is_empty() { - let ident_hi = context.codemap.span_after(item.span, &format!("{}", item.ident)); + let ident_hi = context + .codemap + .span_after(item.span, &format!("{}", item.ident)); let bound_hi = type_param_bounds.last().unwrap().span().hi(); let snippet = context.snippet(mk_sp(ident_hi, bound_hi)); if contains_comment(&snippet) { diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 4353efac4ec7..06b31340d882 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -45,6 +45,11 @@ some_ridiculously_loooooooooooooooooooooong_function(10000 * 30000000000 + 40000 + 2 + 3 { } + if let ast::ItemKind::Trait(_, unsafety, ref generics, ref type_param_bounds, ref trait_items) = item.node + { + // nothing + } + let test = if true { 5 } else { 3 }; if cond() { diff --git a/tests/target/expr.rs b/tests/target/expr.rs index fff0650f4599..edf83b66fc4a 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -70,6 +70,12 @@ fn foo() -> bool { ) = 1 + 2 + 3 {} + if let ast::ItemKind::Trait(_, unsafety, ref generics, ref type_param_bounds, ref trait_items) = + item.node + { + // nothing + } + let test = if true { 5 } else { 3 }; if cond() {