diff --git a/src/config.rs b/src/config.rs index 7a64ab15916..3990e1af6ad 100644 --- a/src/config.rs +++ b/src/config.rs @@ -266,6 +266,7 @@ create_config! { "Maximum width in the body of a struct lit before falling back to vertical formatting"; newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings"; fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions"; + item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums"; fn_return_indent: ReturnIndent, ReturnIndent::WithArgs, "Location of return type in function declaration"; fn_args_paren_newline: bool, true, "If function argument parenthesis goes on a newline"; @@ -302,5 +303,4 @@ create_config! { take_source_hints: bool, true, "Retain some formatting characteristics from the source code"; hard_tabs: bool, false, "Use tab characters for indentation, spaces for alignment"; wrap_comments: bool, false, "Break comments to fit on the line"; - item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums"; } diff --git a/tests/source/item-brace-style-next-line.rs b/tests/source/item-brace-style-next-line.rs new file mode 100644 index 00000000000..96a628349ea --- /dev/null +++ b/tests/source/item-brace-style-next-line.rs @@ -0,0 +1,29 @@ +// rustfmt-item_brace_style: AlwaysNextLine + +mod M { + enum A { + A, + } + + struct B { + b: i32, + } + + // For empty enums and structs, the brace remains on the same line. + enum C {} + + struct D {} + + enum A where T: Copy { + A, + } + + struct B where T: Copy { + b: i32, + } + + // For empty enums and structs, the brace remains on the same line. + enum C where T: Copy {} + + struct D where T: Copy {} +} diff --git a/tests/source/item-brace-style-same-line.rs b/tests/source/item-brace-style-same-line.rs new file mode 100644 index 00000000000..636a584ff68 --- /dev/null +++ b/tests/source/item-brace-style-same-line.rs @@ -0,0 +1,29 @@ +// rustfmt-item_brace_style: PreferSameLine + +mod M { + enum A + { + A, + } + + struct B + { + b: i32, + } + + enum C {} + + struct D {} + + enum A where T: Copy { + A, + } + + struct B where T: Copy { + b: i32, + } + + enum C where T: Copy {} + + struct D where T: Copy {} +} diff --git a/tests/source/item-brace-style.rs b/tests/source/item-brace-style.rs deleted file mode 100644 index 37b02f0940a..00000000000 --- a/tests/source/item-brace-style.rs +++ /dev/null @@ -1,16 +0,0 @@ -// rustfmt-item_brace_style: AlwaysNextLine - -mod M { - enum A { - A, - } - - struct B { - b: i32, - } - - // For empty enums and structs, the brace remains on the same line. - enum C {} - - struct D {} -} diff --git a/tests/target/item-brace-style-next-line.rs b/tests/target/item-brace-style-next-line.rs new file mode 100644 index 00000000000..a5c24102d92 --- /dev/null +++ b/tests/target/item-brace-style-next-line.rs @@ -0,0 +1,39 @@ +// rustfmt-item_brace_style: AlwaysNextLine + +mod M { + enum A + { + A, + } + + struct B + { + b: i32, + } + + // For empty enums and structs, the brace remains on the same line. + enum C {} + + struct D {} + + enum A + where T: Copy + { + A, + } + + struct B + where T: Copy + { + b: i32, + } + + // For empty enums and structs, the brace remains on the same line. + enum C + where T: Copy + {} + + struct D + where T: Copy + {} +} diff --git a/tests/target/item-brace-style-same-line.rs b/tests/target/item-brace-style-same-line.rs new file mode 100644 index 00000000000..b38bd2e1a19 --- /dev/null +++ b/tests/target/item-brace-style-same-line.rs @@ -0,0 +1,31 @@ +// rustfmt-item_brace_style: PreferSameLine + +mod M { + enum A { + A, + } + + struct B { + b: i32, + } + + enum C {} + + struct D {} + + enum A + where T: Copy { + A, + } + + struct B + where T: Copy { + b: i32, + } + + enum C + where T: Copy {} + + struct D + where T: Copy {} +} diff --git a/tests/target/item-brace-style.rs b/tests/target/item-brace-style.rs deleted file mode 100644 index 006d6b4d3bf..00000000000 --- a/tests/target/item-brace-style.rs +++ /dev/null @@ -1,18 +0,0 @@ -// rustfmt-item_brace_style: AlwaysNextLine - -mod M { - enum A - { - A, - } - - struct B - { - b: i32, - } - - // For empty enums and structs, the brace remains on the same line. - enum C {} - - struct D {} -}