From 366ff40ae7fed8380cb3a421d6924ddb6485c234 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 19 Dec 2017 09:41:05 +0900 Subject: [PATCH] Take the width of block's prefix into account only once --- src/expr.rs | 3 +-- tests/source/expr.rs | 6 ++++++ tests/target/closure.rs | 9 +++------ tests/target/expr.rs | 7 +++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 8ef55b1716c..dc2743425ec 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -608,7 +608,7 @@ fn rewrite_single_line_block( shape: Shape, ) -> Option { if is_simple_block(block, context.codemap) { - let expr_shape = Shape::legacy(shape.width - prefix.len(), shape.indent); + let expr_shape = shape.offset_left(last_line_width(prefix))?; let expr_str = block.stmts[0].rewrite(context, expr_shape)?; let result = format!("{}{{ {} }}", prefix, expr_str); if result.len() <= shape.width && !result.contains('\n') { @@ -654,7 +654,6 @@ impl Rewrite for ast::Block { } let prefix = block_prefix(context, self, shape)?; - let shape = shape.offset_left(last_line_width(&prefix))?; let result = rewrite_block_with_visitor(context, &prefix, self, shape, true); if let Some(ref result_str) = result { diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 06b31340d88..f87c950735f 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -108,6 +108,12 @@ fn baz() { unsafe { foo(); } + + // #2289 + let identifier_0 = unsafe { this_is_58_chars_long_and_line_is_93_chars_long_xxxxxxxxxx }; + let identifier_1 = unsafe { this_is_59_chars_long_and_line_is_94_chars_long_xxxxxxxxxxx }; + let identifier_2 = unsafe { this_is_65_chars_long_and_line_is_100_chars_long_xxxxxxxxxxxxxxxx }; + let identifier_3 = unsafe { this_is_66_chars_long_and_line_is_101_chars_long_xxxxxxxxxxxxxxxxx }; } // Test some empty blocks. diff --git a/tests/target/closure.rs b/tests/target/closure.rs index 1912c16ef6e..5bc89d58222 100644 --- a/tests/target/closure.rs +++ b/tests/target/closure.rs @@ -123,9 +123,7 @@ fn foo() { fn issue1405() { open_raw_fd(fd, b'r').and_then(|file| { - Capture::new_raw(None, |_, err| unsafe { - raw::pcap_fopen_offline(file, err) - }) + Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) }) }); } @@ -176,9 +174,8 @@ fn issue1329() { } fn issue325() { - let f = || unsafe { - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - }; + let f = + || unsafe { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }; } fn issue1697() { diff --git a/tests/target/expr.rs b/tests/target/expr.rs index edf83b66fc4..3c5d85b7d76 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -147,6 +147,13 @@ fn baz() { unsafe { foo(); } + + // #2289 + let identifier_0 = unsafe { this_is_58_chars_long_and_line_is_93_chars_long_xxxxxxxxxx }; + let identifier_1 = unsafe { this_is_59_chars_long_and_line_is_94_chars_long_xxxxxxxxxxx }; + let identifier_2 = unsafe { this_is_65_chars_long_and_line_is_100_chars_long_xxxxxxxxxxxxxxxx }; + let identifier_3 = + unsafe { this_is_66_chars_long_and_line_is_101_chars_long_xxxxxxxxxxxxxxxxx }; } // Test some empty blocks.