From 90619b648413831b3e33947ca9792b966c2a953d Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Wed, 20 Jul 2022 21:55:44 -0400 Subject: [PATCH 1/7] Improvements: Adding the test cases (source and target) for the issue 3071. --- tests/source/issue-3071.rs | 12 ++++++++++++ tests/target/issue-3071.rs | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/source/issue-3071.rs create mode 100644 tests/target/issue-3071.rs diff --git a/tests/source/issue-3071.rs b/tests/source/issue-3071.rs new file mode 100644 index 00000000000..ed95af704ce --- /dev/null +++ b/tests/source/issue-3071.rs @@ -0,0 +1,12 @@ +// indent_style=Visual + +struct A + where T: Send +{ + x: u32, +} + +impl A where T: Send +{ + fn foo() {} +} diff --git a/tests/target/issue-3071.rs b/tests/target/issue-3071.rs new file mode 100644 index 00000000000..104456f1e6e --- /dev/null +++ b/tests/target/issue-3071.rs @@ -0,0 +1,15 @@ +// indent_style=Visual + +struct A +where + T: Send, +{ + x: u32, +} + +impl A +where + T: Send, +{ + fn foo() {} +} From 90a279d7790e3296909c75db584a68ae48f81668 Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Thu, 21 Jul 2022 11:37:35 -0400 Subject: [PATCH 2/7] Improvements: Now the tests cases associated with the issue implement the required indent_style config. --- tests/source/issue-3071.rs | 2 +- tests/target/issue-3071.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/source/issue-3071.rs b/tests/source/issue-3071.rs index ed95af704ce..b87c0690d31 100644 --- a/tests/source/issue-3071.rs +++ b/tests/source/issue-3071.rs @@ -1,4 +1,4 @@ -// indent_style=Visual +// rustfmt-indent_style: Visual struct A where T: Send diff --git a/tests/target/issue-3071.rs b/tests/target/issue-3071.rs index 104456f1e6e..7a4cfb36d25 100644 --- a/tests/target/issue-3071.rs +++ b/tests/target/issue-3071.rs @@ -1,15 +1,13 @@ -// indent_style=Visual +// rustfmt-indent_style: Visual struct A -where - T: Send, + where T: Send { x: u32, } impl A -where - T: Send, + where T: Send { fn foo() {} } From c84d25311697abbc9968404a8230b1ff4e0ab31c Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Thu, 21 Jul 2022 13:50:59 -0400 Subject: [PATCH 3/7] Improvements: Setting the on_new_line parameter to true on the format_impl function. --- src/items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items.rs b/src/items.rs index a76e88b77d4..924d073d058 100644 --- a/src/items.rs +++ b/src/items.rs @@ -697,7 +697,7 @@ pub(crate) fn format_impl( generics.where_clause.span, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), - false, + true, "{", where_span_end, self_ty.span.hi(), From 6b89a7581d7a9d50ed9c8d66aa4c9f1c16573d68 Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Thu, 21 Jul 2022 13:57:36 -0400 Subject: [PATCH 4/7] Improvements: Adding additional test-cases. --- tests/source/issue-3071.rs | 13 +++++++++++++ tests/target/issue-3071.rs | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/source/issue-3071.rs b/tests/source/issue-3071.rs index b87c0690d31..81085815ddf 100644 --- a/tests/source/issue-3071.rs +++ b/tests/source/issue-3071.rs @@ -10,3 +10,16 @@ impl A where T: Send { fn foo() {} } + + +struct B + where T: Send, + K: Eq +{ + y: u32, +} + +impl B where T: Send, K: Eq +{ + fn bar() {} +} diff --git a/tests/target/issue-3071.rs b/tests/target/issue-3071.rs index 7a4cfb36d25..9f55e837575 100644 --- a/tests/target/issue-3071.rs +++ b/tests/target/issue-3071.rs @@ -11,3 +11,17 @@ impl A { fn foo() {} } + +struct B + where T: Send, + K: Eq +{ + y: u32, +} + +impl B + where T: Send, + K: Eq +{ + fn bar() {} +} From af2b711b51fe8a5ea3fe535e5e55bc6f6517874c Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Wed, 17 Aug 2022 14:21:22 -0400 Subject: [PATCH 5/7] Improvements: The test cases for the issue-3071 were moved into a folder. Additional test cases for the issue-3071 were added; in order to check if the the where_single_line config still has the expected behaviour. Additional examples were added to Configurations.md. --- Configurations.md | 26 +++++++++++++++++ .../issue-3071-where-single-line.rs | 26 +++++++++++++++++ tests/source/{ => issue-3071}/issue-3071.rs | 0 .../issue-3071-where-single-line.rs | 28 +++++++++++++++++++ tests/target/{ => issue-3071}/issue-3071.rs | 0 5 files changed, 80 insertions(+) create mode 100644 tests/source/issue-3071/issue-3071-where-single-line.rs rename tests/source/{ => issue-3071}/issue-3071.rs (100%) create mode 100644 tests/target/issue-3071/issue-3071-where-single-line.rs rename tests/target/{ => issue-3071}/issue-3071.rs (100%) diff --git a/Configurations.md b/Configurations.md index eaff09431ac..0855313f2bb 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1615,6 +1615,20 @@ where { // body } + +struct Foo +where + T: PartialEq, +{ + // body +} + +impl Foo +where + T: PartialEq, +{ + // body +} ``` #### `"Visual"`: @@ -1628,6 +1642,18 @@ fn lorem() -> T { // body } + +struct Foo + where T: PartialEq +{ + // body +} + +impl Foo + where T: PartialEq +{ + // body +} ``` ## `inline_attribute_width` diff --git a/tests/source/issue-3071/issue-3071-where-single-line.rs b/tests/source/issue-3071/issue-3071-where-single-line.rs new file mode 100644 index 00000000000..5dc8857d9b9 --- /dev/null +++ b/tests/source/issue-3071/issue-3071-where-single-line.rs @@ -0,0 +1,26 @@ +// rustfmt-indent_style: Visual +// rustfmt-where_single_line: true + +struct A + where T: Send +{ + x: u32, +} + +impl A where T: Send +{ + fn foo() {} +} + + +struct B + where T: Send, + K: Eq +{ + y: u32, +} + +impl B where T: Send, K: Eq +{ + fn bar() {} +} diff --git a/tests/source/issue-3071.rs b/tests/source/issue-3071/issue-3071.rs similarity index 100% rename from tests/source/issue-3071.rs rename to tests/source/issue-3071/issue-3071.rs diff --git a/tests/target/issue-3071/issue-3071-where-single-line.rs b/tests/target/issue-3071/issue-3071-where-single-line.rs new file mode 100644 index 00000000000..8b807b9e4a5 --- /dev/null +++ b/tests/target/issue-3071/issue-3071-where-single-line.rs @@ -0,0 +1,28 @@ +// rustfmt-indent_style: Visual +// rustfmt-where_single_line: true + +struct A + where T: Send +{ + x: u32, +} + +impl A + where T: Send +{ + fn foo() {} +} + +struct B + where T: Send, + K: Eq +{ + y: u32, +} + +impl B + where T: Send, + K: Eq +{ + fn bar() {} +} diff --git a/tests/target/issue-3071.rs b/tests/target/issue-3071/issue-3071.rs similarity index 100% rename from tests/target/issue-3071.rs rename to tests/target/issue-3071/issue-3071.rs From 841b4542fd328387b4e9965126f80b8438d6592b Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Wed, 17 Aug 2022 14:27:31 -0400 Subject: [PATCH 6/7] Improvements: Replacing PartialEq with Eq on configurations.md --- Configurations.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Configurations.md b/Configurations.md index 0855313f2bb..f402e152aa5 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1618,14 +1618,14 @@ where struct Foo where - T: PartialEq, + T: Eq, { // body } impl Foo where - T: PartialEq, + T: Eq, { // body } @@ -1644,13 +1644,13 @@ fn lorem() -> T } struct Foo - where T: PartialEq + where T: Eq { // body } impl Foo - where T: PartialEq + where T: Eq { // body } From 416a1a71f0d022d2932d25d5d40d305f0e4e2f04 Mon Sep 17 00:00:00 2001 From: Martin Juarez Date: Thu, 18 Aug 2022 09:49:46 -0400 Subject: [PATCH 7/7] Improvements: Removing the where clause examples for structs and impl blocks from configurations.md. --- Configurations.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/Configurations.md b/Configurations.md index f402e152aa5..eaff09431ac 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1615,20 +1615,6 @@ where { // body } - -struct Foo -where - T: Eq, -{ - // body -} - -impl Foo -where - T: Eq, -{ - // body -} ``` #### `"Visual"`: @@ -1642,18 +1628,6 @@ fn lorem() -> T { // body } - -struct Foo - where T: Eq -{ - // body -} - -impl Foo - where T: Eq -{ - // body -} ``` ## `inline_attribute_width`