From 5d6399830fbecd28aa32c16886543e46f1ca32ee Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Fri, 2 Sep 2022 16:47:59 -0400 Subject: [PATCH 1/4] Adding test cases for the issue. --- tests/source/issue-5525.rs | 7 +++++++ tests/target/issue-5525.rs | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/source/issue-5525.rs create mode 100644 tests/target/issue-5525.rs diff --git a/tests/source/issue-5525.rs b/tests/source/issue-5525.rs new file mode 100644 index 00000000000..78c03eb6f97 --- /dev/null +++ b/tests/source/issue-5525.rs @@ -0,0 +1,7 @@ +pub struct SomeCallback( + pub extern "C" fn( + long_argument_name_to_avoid_wrap: u32, + second_long_argument_name: u32, + third_long_argument_name: u32, + ), +); \ No newline at end of file diff --git a/tests/target/issue-5525.rs b/tests/target/issue-5525.rs new file mode 100644 index 00000000000..ab56ed43f91 --- /dev/null +++ b/tests/target/issue-5525.rs @@ -0,0 +1,7 @@ +pub struct SomeCallback( + pub extern "C" fn( + long_argument_name_to_avoid_wrap: u32, + second_long_argument_name: u32, + third_long_argument_name: u32, + ), +); From 4fa94aedeb9771cca4b3a8599abfed269e15fadb Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Wed, 7 Sep 2022 09:41:20 -0400 Subject: [PATCH 2/4] Improvements: Adding some logs in order to gather insight in regards to the flow of the rewrite_assign_rhs_expr function. --- src/expr.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/expr.rs b/src/expr.rs index c9d704765c2..edfa9bc120c 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1984,6 +1984,12 @@ pub(crate) fn rewrite_assign_rhs_with, R: Rewrite>( ) -> Option { let lhs = lhs.into(); let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_kind, rhs_tactics)?; + let mut complete_str = String::new(); + complete_str.push_str(&lhs); + complete_str.push_str(&rhs); + println!("Right hand side"); + dbg!(complete_str); + println!("Right hand side"); Some(lhs + &rhs) } From da0be5a358a51092df5d51dae0561c3293ce3fc1 Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Mon, 19 Sep 2022 09:45:54 -0400 Subject: [PATCH 3/4] Improvements: Now we remove extra whitespace on the rewrite_assign_rhs_with function (expr.rs - 1977) if the lhs expression ends with whitespace and the rhs expressions starts with whitespace. --- src/expr.rs | 9 +++------ tests/source/issue-5525.rs | 2 ++ tests/target/issue-5525.rs | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index edfa9bc120c..52b33ea1a26 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1984,12 +1984,9 @@ pub(crate) fn rewrite_assign_rhs_with, R: Rewrite>( ) -> Option { let lhs = lhs.into(); let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_kind, rhs_tactics)?; - let mut complete_str = String::new(); - complete_str.push_str(&lhs); - complete_str.push_str(&rhs); - println!("Right hand side"); - dbg!(complete_str); - println!("Right hand side"); + if context.config.version() == Version::Two && lhs.ends_with(" ") && rhs.starts_with(" ") { + return Some(lhs + &rhs.trim_start()); + } Some(lhs + &rhs) } diff --git a/tests/source/issue-5525.rs b/tests/source/issue-5525.rs index 78c03eb6f97..d086afab8f4 100644 --- a/tests/source/issue-5525.rs +++ b/tests/source/issue-5525.rs @@ -1,3 +1,5 @@ +// rustfmt-version: Two + pub struct SomeCallback( pub extern "C" fn( long_argument_name_to_avoid_wrap: u32, diff --git a/tests/target/issue-5525.rs b/tests/target/issue-5525.rs index ab56ed43f91..e339b7e0526 100644 --- a/tests/target/issue-5525.rs +++ b/tests/target/issue-5525.rs @@ -1,3 +1,5 @@ +// rustfmt-version: Two + pub struct SomeCallback( pub extern "C" fn( long_argument_name_to_avoid_wrap: u32, From d0cfb576e0784b3dd74ecb909f928ee5d56b0120 Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Wed, 21 Sep 2022 07:53:42 -0400 Subject: [PATCH 4/4] Removing the file test/source/issue-5525.rs, since it's not required for idempotence tests. --- tests/source/issue-5525.rs | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 tests/source/issue-5525.rs diff --git a/tests/source/issue-5525.rs b/tests/source/issue-5525.rs deleted file mode 100644 index d086afab8f4..00000000000 --- a/tests/source/issue-5525.rs +++ /dev/null @@ -1,9 +0,0 @@ -// rustfmt-version: Two - -pub struct SomeCallback( - pub extern "C" fn( - long_argument_name_to_avoid_wrap: u32, - second_long_argument_name: u32, - third_long_argument_name: u32, - ), -); \ No newline at end of file