From c2804589a1d848f6382da919e91b903843f8328f Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 21 Nov 2017 08:50:55 +0900 Subject: [PATCH 1/3] Add a test for assignment whose lhs is exactly 100 chars --- tests/source/expr.rs | 5 +++++ tests/target/expr.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 1a8d35f2f0c..4f7a7fb70a7 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 08803e5db4e..f67c149b542 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() { From 34b0c9cf3fcf83a1f356b3d75430a0ac8b1f1790 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 21 Nov 2017 08:52:11 +0900 Subject: [PATCH 2/3] Do not give up when we run out of space when choosing rhs --- src/expr.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index d3c3e760a27..ad74f11ddcd 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2635,7 +2635,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) } From 59ebde26f795c41665637d6d0a939a6711fe638a Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 21 Nov 2017 08:52:43 +0900 Subject: [PATCH 3/3] Cargo fmt --- src/items.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/items.rs b/src/items.rs index 3fe82f48ea5..a202a17d34f 100644 --- a/src/items.rs +++ b/src/items.rs @@ -955,7 +955,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) {