diff --git a/src/config.rs b/src/config.rs index 03b522be366..b788052a047 100644 --- a/src/config.rs +++ b/src/config.rs @@ -92,6 +92,7 @@ create_config! { fn_args_layout: Density, fn_arg_indent: BlockIndentStyle, where_indent: BlockIndentStyle, // Visual will be treated like Tabbed + where_layout: ListTactic, generics_indent: BlockIndentStyle, struct_trailing_comma: SeparatorTactic, struct_lit_trailing_comma: SeparatorTactic, @@ -120,6 +121,7 @@ impl Default for Config { fn_args_layout: Density::Tall, fn_arg_indent: BlockIndentStyle::Visual, where_indent: BlockIndentStyle::Tabbed, + where_layout: ListTactic::Vertical, generics_indent: BlockIndentStyle::Visual, struct_trailing_comma: SeparatorTactic::Vertical, struct_lit_trailing_comma: SeparatorTactic::Vertical, diff --git a/src/items.rs b/src/items.rs index 94083e81c11..d2265fe9db1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -823,7 +823,7 @@ impl<'a> FmtVisitor<'a> { span_end); let fmt = ListFormatting { - tactic: ListTactic::Vertical, + tactic: self.config.where_layout, separator: ",", trailing_separator: SeparatorTactic::Never, indent: offset, diff --git a/src/lists.rs b/src/lists.rs index 931baaa1073..3b9bb3f4af2 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -28,6 +28,8 @@ pub enum ListTactic { Mixed, } +impl_enum_decodable!(ListTactic, Vertical, Horizontal, HorizontalVertical, Mixed); + #[derive(Eq, PartialEq, Debug, Copy, Clone)] pub enum SeparatorTactic { Always, diff --git a/tests/config/small_tabs.toml b/tests/config/small_tabs.toml index 3d6f01d7375..21d12c7d4ea 100644 --- a/tests/config/small_tabs.toml +++ b/tests/config/small_tabs.toml @@ -9,6 +9,7 @@ fn_args_paren_newline = true fn_args_layout = "Tall" fn_arg_indent = "Visual" where_indent = "Tabbed" +where_layout = "Vertical" generics_indent = "Visual" struct_trailing_comma = "Vertical" struct_lit_trailing_comma = "Vertical" diff --git a/tests/source/fn-custom-2.rs b/tests/source/fn-custom-2.rs index 6c9238e8087..a45f5501ea7 100644 --- a/tests/source/fn-custom-2.rs +++ b/tests/source/fn-custom-2.rs @@ -1,6 +1,7 @@ // rustfmt-fn_arg_indent: Inherit // rustfmt-generics_indent: Tabbed // rustfmt-where_indent: Inherit +// rustfmt-where_layout: Mixed // Test different indents. fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { @@ -15,6 +16,10 @@ fn baz() where X: TTTTTTTT { baz(); } +fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT { + baz(); +} + impl Foo { fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { foo(); diff --git a/tests/source/fn-custom-3.rs b/tests/source/fn-custom-3.rs index 68939eee6b5..e63b642d19c 100644 --- a/tests/source/fn-custom-3.rs +++ b/tests/source/fn-custom-3.rs @@ -1,5 +1,6 @@ // rustfmt-fn_arg_indent: Tabbed // rustfmt-generics_indent: Inherit +// rustfmt-where_layout: HorizontalVertical // Test different indents. fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { @@ -10,6 +11,14 @@ fn bar<'a: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb, TTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUU: WW bar(); } +fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT { + baz(); +} + +fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT { + baz(); +} + impl Foo { fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { foo(); diff --git a/tests/target/fn-custom-2.rs b/tests/target/fn-custom-2.rs index e5c8af9a38b..acac301fa53 100644 --- a/tests/target/fn-custom-2.rs +++ b/tests/target/fn-custom-2.rs @@ -1,6 +1,7 @@ // rustfmt-fn_arg_indent: Inherit // rustfmt-generics_indent: Tabbed // rustfmt-where_indent: Inherit +// rustfmt-where_layout: Mixed // Test different indents. fn foo(a: Aaaaaaaaaaaaaaa, @@ -24,6 +25,13 @@ where X: TTTTTTTT baz(); } +fn qux() +where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT +{ + baz(); +} + impl Foo { fn foo(self, a: Aaaaaaaaaaaaaaa, diff --git a/tests/target/fn-custom-3.rs b/tests/target/fn-custom-3.rs index 61194dd04f3..110fcf36714 100644 --- a/tests/target/fn-custom-3.rs +++ b/tests/target/fn-custom-3.rs @@ -1,5 +1,6 @@ // rustfmt-fn_arg_indent: Tabbed // rustfmt-generics_indent: Inherit +// rustfmt-where_layout: HorizontalVertical // Test different indents. fn foo(a: Aaaaaaaaaaaaaaa, @@ -17,6 +18,21 @@ UUUUUUUUUUUUUUUUUUUU: WWWWWWWWWWWWWWWWWWWWWWWW> bar(); } +fn qux() + where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT +{ + baz(); +} + +fn qux() + where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, + X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT +{ + baz(); +} + impl Foo { fn foo(self, a: Aaaaaaaaaaaaaaa,