diff --git a/Configurations.md b/Configurations.md index 400ad8c5d3b..50d0c5e370d 100644 --- a/Configurations.md +++ b/Configurations.md @@ -243,7 +243,7 @@ fn lorem(ipsum: usize) { fn lorem(ipsum: T) where - T: Add + Sub + Mul + Div, { + T: Add + Sub + Mul + Div { // body } ``` @@ -290,7 +290,7 @@ struct Lorem { struct Dolor where - T: Eq, { + T: Eq { sit: T, } ``` diff --git a/src/items.rs b/src/items.rs index 755a41f6bf0..43ce5b8731b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2751,6 +2751,7 @@ fn rewrite_where_clause_rfc_style( span_end: Option, span_end_before_where: BytePos, where_clause_option: WhereClauseOption, + brace_style: BraceStyle, ) -> Option { let (where_keyword, allow_single_line) = rewrite_where_keyword( context, @@ -2779,6 +2780,7 @@ fn rewrite_where_clause_rfc_style( span_end, where_clause_option, force_single_line, + brace_style, )?; // 6 = `where ` @@ -2850,6 +2852,7 @@ fn rewrite_bounds_on_where_clause( span_end: Option, where_clause_option: WhereClauseOption, force_single_line: bool, + brace_style: BraceStyle, ) -> Option { let span_start = predicates[0].span().lo(); // If we don't have the start of the next span, then use the end of the @@ -2869,7 +2872,11 @@ fn rewrite_bounds_on_where_clause( span_end, false, ); - let comma_tactic = if where_clause_option.suppress_comma || force_single_line { + let comma_tactic = if where_clause_option.suppress_comma + || force_single_line + || brace_style == BraceStyle::PreferSameLine + && context.config.trailing_comma() == SeparatorTactic::Vertical + { SeparatorTactic::Never } else { context.config.trailing_comma() @@ -2916,6 +2923,7 @@ fn rewrite_where_clause( span_end, span_end_before_where, where_clause_option, + brace_style, ); } diff --git a/tests/target/configs/brace_style/fn_prefer_same_line.rs b/tests/target/configs/brace_style/fn_prefer_same_line.rs index 23f98b6dd7a..f57a2517f98 100644 --- a/tests/target/configs/brace_style/fn_prefer_same_line.rs +++ b/tests/target/configs/brace_style/fn_prefer_same_line.rs @@ -11,6 +11,6 @@ fn lorem(ipsum: usize) { fn lorem(ipsum: T) where - T: Add + Sub + Mul + Div, { + T: Add + Sub + Mul + Div { // body } diff --git a/tests/target/configs/brace_style/item_prefer_same_line.rs b/tests/target/configs/brace_style/item_prefer_same_line.rs index 5143d7517c7..6c9b73800db 100644 --- a/tests/target/configs/brace_style/item_prefer_same_line.rs +++ b/tests/target/configs/brace_style/item_prefer_same_line.rs @@ -7,7 +7,7 @@ struct Lorem { struct Dolor where - T: Eq, { + T: Eq { sit: T, } diff --git a/tests/target/fn-custom-6.rs b/tests/target/fn-custom-6.rs index e891f4d5882..a54c3b4e501 100644 --- a/tests/target/fn-custom-6.rs +++ b/tests/target/fn-custom-6.rs @@ -31,7 +31,7 @@ fn bar( fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { foo(); } @@ -42,13 +42,13 @@ fn bar( d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee, ) where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { bar(); } fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { foo(); } @@ -60,7 +60,7 @@ fn bar( e: Eeeeeeeeeeeeeee, ) -> String where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { bar(); } diff --git a/tests/target/fn-custom-8.rs b/tests/target/fn-custom-8.rs index 29af3fca79d..14fd8409349 100644 --- a/tests/target/fn-custom-8.rs +++ b/tests/target/fn-custom-8.rs @@ -31,7 +31,7 @@ fn bar( fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { foo(); } @@ -42,13 +42,13 @@ fn bar( d: Dddddddddddddddd, e: Eeeeeeeeeeeeeee, ) where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { bar(); } fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) -> String where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { foo(); } @@ -60,7 +60,7 @@ fn bar( e: Eeeeeeeeeeeeeee, ) -> String where - T: UUUUUUUUUUU, { + T: UUUUUUUUUUU { bar(); } @@ -72,6 +72,6 @@ trait Test { fn bar(a: u8) -> String where Foo: foooo, - Bar: barrr, { + Bar: barrr { } } diff --git a/tests/target/issue-2321/trailing_comma_always_and_brace_style_always_next_line.rs b/tests/target/issue-2321/trailing_comma_always_and_brace_style_always_next_line.rs new file mode 100644 index 00000000000..78605412509 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_always_and_brace_style_always_next_line.rs @@ -0,0 +1,10 @@ +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-trailing_comma: Always + +fn lorem(lorem: S, ipsum: T,) +where + S: Add + Sub, + T: Mul + Div, +{ + // body +} diff --git a/tests/target/issue-2321/trailing_comma_always_and_brace_style_prefer_same_line.rs b/tests/target/issue-2321/trailing_comma_always_and_brace_style_prefer_same_line.rs new file mode 100644 index 00000000000..64262c96d59 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_always_and_brace_style_prefer_same_line.rs @@ -0,0 +1,9 @@ +// rustfmt-brace_style: PreferSameLine +// rustfmt-trailing_comma: Always + +fn lorem(lorem: S, ipsum: T,) +where + S: Add + Sub, + T: Mul + Div, { + // body +} diff --git a/tests/target/issue-2321/trailing_comma_always_and_brace_style_same_line_where.rs b/tests/target/issue-2321/trailing_comma_always_and_brace_style_same_line_where.rs new file mode 100644 index 00000000000..fecce851d99 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_always_and_brace_style_same_line_where.rs @@ -0,0 +1,10 @@ +// rustfmt-brace_style: SameLineWhere +// rustfmt-trailing_comma: Always + +fn lorem(lorem: S, ipsum: T,) +where + S: Add + Sub, + T: Mul + Div, +{ + // body +} diff --git a/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_always_next_line.rs b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_always_next_line.rs new file mode 100644 index 00000000000..b759cfe9360 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_always_next_line.rs @@ -0,0 +1,10 @@ +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-trailing_comma: Vertical + +fn lorem(lorem: S, ipsum: T) +where + S: Add + Sub, + T: Mul + Div, +{ + // body +} diff --git a/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_prefer_same_line.rs b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_prefer_same_line.rs new file mode 100644 index 00000000000..77553f643d7 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_prefer_same_line.rs @@ -0,0 +1,9 @@ +// rustfmt-brace_style: PreferSameLine +// rustfmt-trailing_comma: Vertical + +fn lorem(lorem: S, ipsum: T) +where + S: Add + Sub, + T: Mul + Div { + // body +} diff --git a/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_same_line_where.rs b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_same_line_where.rs new file mode 100644 index 00000000000..4e4b8bbaec3 --- /dev/null +++ b/tests/target/issue-2321/trailing_comma_vertical_and_brace_style_same_line_where.rs @@ -0,0 +1,10 @@ +// rustfmt-brace_style: SameLineWhere +// rustfmt-trailing_comma: Vertical + +fn lorem(lorem: S, ipsum: T) +where + S: Add + Sub, + T: Mul + Div, +{ + // body +} diff --git a/tests/target/item-brace-style-prefer-same-line.rs b/tests/target/item-brace-style-prefer-same-line.rs index ef8dc028c2d..e1ffdf999ba 100644 --- a/tests/target/item-brace-style-prefer-same-line.rs +++ b/tests/target/item-brace-style-prefer-same-line.rs @@ -15,21 +15,21 @@ mod M { enum A where - T: Copy, { + T: Copy { A, } struct B where - T: Copy, { + T: Copy { b: i32, } enum C where - T: Copy, {} + T: Copy {} struct D where - T: Copy, {} + T: Copy {} }