Skip to content

Commit f8074b3

Browse files
committed
Combine fn_brace_style and item_brace_style
1 parent bf15438 commit f8074b3

29 files changed

+50
-49
lines changed

src/config.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,7 @@ create_config! {
538538
"Maximum width in the body of a struct variant before falling back to vertical formatting";
539539
force_explicit_abi: bool, true, false, "Always print the abi for extern items";
540540
newline_style: NewlineStyle, NewlineStyle::Unix, false, "Unix or Windows line endings";
541-
fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for functions";
542-
item_brace_style: BraceStyle, BraceStyle::SameLineWhere, false,
543-
"Brace style for structs and enums";
541+
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
544542
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
545543
"Brace style for control flow constructs";
546544
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";

src/items.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'a> FmtVisitor<'a> {
314314
rewrite_fn_base(&context, indent, ident, fn_sig, span, newline_brace, true)?;
315315

316316
// 2 = ` {`
317-
if self.config.fn_brace_style() == BraceStyle::AlwaysNextLine || force_newline_brace
317+
if self.config.brace_style() == BraceStyle::AlwaysNextLine || force_newline_brace
318318
|| last_line_width(&result) + 2 > self.shape().width
319319
{
320320
newline_brace = true;
@@ -440,7 +440,7 @@ impl<'a> FmtVisitor<'a> {
440440
let generics_str = format_generics(
441441
&self.get_context(),
442442
generics,
443-
self.config.item_brace_style(),
443+
self.config.brace_style(),
444444
if enum_def.variants.is_empty() {
445445
BracePos::ForceSameLine
446446
} else {
@@ -595,7 +595,7 @@ pub fn format_impl(
595595
let where_clause_str = rewrite_where_clause(
596596
context,
597597
&generics.where_clause,
598-
context.config.item_brace_style(),
598+
context.config.brace_style(),
599599
Shape::legacy(where_budget, offset.block_only()),
600600
context.config.where_density(),
601601
"{",
@@ -641,7 +641,7 @@ pub fn format_impl(
641641
}
642642
result.push_str(&where_clause_str);
643643

644-
match context.config.item_brace_style() {
644+
match context.config.brace_style() {
645645
_ if last_line_contains_single_line_comment(&result) => result.push_str(&sep),
646646
BraceStyle::AlwaysNextLine => result.push_str(&sep),
647647
BraceStyle::PreferSameLine => result.push(' '),
@@ -784,7 +784,7 @@ fn format_impl_ref_and_type(
784784
let curly_brace_overhead = if generics.where_clause.predicates.is_empty() {
785785
// If there is no where clause adapt budget for type formatting to take space and curly
786786
// brace into account.
787-
match context.config.item_brace_style() {
787+
match context.config.brace_style() {
788788
BraceStyle::AlwaysNextLine => 0,
789789
_ => 2,
790790
}
@@ -994,7 +994,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
994994
let where_clause_str = rewrite_where_clause(
995995
context,
996996
&generics.where_clause,
997-
context.config.item_brace_style(),
997+
context.config.brace_style(),
998998
Shape::legacy(where_budget, offset.block_only()),
999999
where_density,
10001000
"{",
@@ -1038,7 +1038,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
10381038
}
10391039
}
10401040

1041-
match context.config.item_brace_style() {
1041+
match context.config.brace_style() {
10421042
_ if last_line_contains_single_line_comment(&result) => {
10431043
result.push('\n');
10441044
result.push_str(&offset.to_string(context.config));
@@ -1103,7 +1103,7 @@ fn format_unit_struct(context: &RewriteContext, p: &StructParts, offset: Indent)
11031103
format_generics(
11041104
context,
11051105
generics,
1106-
context.config.item_brace_style(),
1106+
context.config.brace_style(),
11071107
BracePos::None,
11081108
offset,
11091109
mk_sp(generics.span.lo(), hi),
@@ -1135,7 +1135,7 @@ pub fn format_struct_struct(
11351135
Some(g) => format_generics(
11361136
context,
11371137
g,
1138-
context.config.item_brace_style(),
1138+
context.config.brace_style(),
11391139
if fields.is_empty() {
11401140
BracePos::ForceSameLine
11411141
} else {
@@ -1148,8 +1148,7 @@ pub fn format_struct_struct(
11481148
None => {
11491149
// 3 = ` {}`, 2 = ` {`.
11501150
let overhead = if fields.is_empty() { 3 } else { 2 };
1151-
if (context.config.item_brace_style() == BraceStyle::AlwaysNextLine
1152-
&& !fields.is_empty())
1151+
if (context.config.brace_style() == BraceStyle::AlwaysNextLine && !fields.is_empty())
11531152
|| context.config.max_width() < overhead + result.len()
11541153
{
11551154
format!("\n{}{{", offset.block_only().to_string(context.config))
@@ -1279,7 +1278,7 @@ fn format_tuple_struct(
12791278
rewrite_where_clause(
12801279
context,
12811280
&generics.where_clause,
1282-
context.config.item_brace_style(),
1281+
context.config.brace_style(),
12831282
Shape::legacy(where_budget, offset.block_only()),
12841283
Density::Compressed,
12851284
";",
@@ -1365,7 +1364,7 @@ pub fn rewrite_type_alias(
13651364
let where_clause_str = rewrite_where_clause(
13661365
context,
13671366
&generics.where_clause,
1368-
context.config.item_brace_style(),
1367+
context.config.brace_style(),
13691368
Shape::legacy(where_budget, indent),
13701369
context.config.where_density(),
13711370
"=",
@@ -2071,7 +2070,7 @@ fn rewrite_fn_base(
20712070
if let Some(where_clause_str) = rewrite_where_clause(
20722071
context,
20732072
where_clause,
2074-
context.config.fn_brace_style(),
2073+
context.config.brace_style(),
20752074
Shape::legacy(budget, indent),
20762075
Density::Compressed,
20772076
"{",
@@ -2090,7 +2089,7 @@ fn rewrite_fn_base(
20902089
let where_clause_str = rewrite_where_clause(
20912090
context,
20922091
where_clause,
2093-
context.config.fn_brace_style(),
2092+
context.config.brace_style(),
20942093
Shape::indented(indent, context.config),
20952094
Density::Tall,
20962095
"{",
@@ -2386,7 +2385,7 @@ fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause, has_body:
23862385
if config.where_single_line() && predicate_count == 1 {
23872386
return false;
23882387
}
2389-
match (config.fn_brace_style(), config.where_density()) {
2388+
match (config.brace_style(), config.where_density()) {
23902389
(BraceStyle::AlwaysNextLine, _) => true,
23912390
(_, Density::Compressed) if predicate_count == 1 => false,
23922391
(_, Density::CompressedIfEmpty) if predicate_count == 1 && !has_body => false,

src/visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'a> FmtVisitor<'a> {
666666
self.buffer.push_str(&ident.to_string());
667667

668668
if is_internal {
669-
match self.config.item_brace_style() {
669+
match self.config.brace_style() {
670670
BraceStyle::AlwaysNextLine => self.buffer
671671
.push_str(&format!("\n{}{{", self.block_indent.to_string(self.config))),
672672
_ => self.buffer.push_str(" {"),

tests/config/small_tabs.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ max_width = 100
22
comment_width = 80
33
tab_spaces = 2
44
newline_style = "Unix"
5-
fn_brace_style = "SameLineWhere"
5+
brace_style = "SameLineWhere"
66
fn_return_indent = "WithArgs"
77
fn_args_paren_newline = true
88
fn_args_density = "Tall"

tests/source/configs-fn_brace_style-always_next_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22
// Function brace style
33

44
fn lorem() {

tests/source/configs-fn_brace_style-prefer_same_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22
// Function brace style
33

44
fn lorem() {

tests/source/configs-fn_brace_style-same_line_where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22
// Function brace style
33

44
fn lorem() {

tests/source/configs-item_brace_style-always_next_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22
// Item brace style
33

44
enum Foo {}

tests/source/configs-item_brace_style-prefer_same_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22
// Item brace style
33

44
struct Lorem {

tests/source/configs-item_brace_style-same_line_where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22
// Item brace style
33

44
struct Lorem {

tests/source/fn-custom-6.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Block
2-
// rustfmt-fn_brace_style: PreferSameLine
2+
// rustfmt-brace_style: PreferSameLine
33
// Test different indents.
44

55
fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {

tests/source/fn-custom-7.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-indent_style: Block
33
// rustfmt-fn_args_density: Vertical
4-
// rustfmt-fn_brace_style: AlwaysNextLine
4+
// rustfmt-brace_style: AlwaysNextLine
55

66
// Case with only one variable.
77
fn foo(a: u8) -> u8 {

tests/source/fn-custom-8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Block
2-
// rustfmt-fn_brace_style: PreferSameLine
2+
// rustfmt-brace_style: PreferSameLine
33
// Test different indents.
44

55
fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {

tests/source/item-brace-style-always-next-line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22

33
mod M {
44
enum A {

tests/source/item-brace-style-prefer-same-line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22

33
mod M {
44
enum A

tests/source/item-brace-style-same-line-where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22

33
mod M {
44
enum A

tests/target/configs-fn_brace_style-always_next_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22
// Function brace style
33

44
fn lorem()

tests/target/configs-fn_brace_style-prefer_same_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22
// Function brace style
33

44
fn lorem() {

tests/target/configs-fn_brace_style-same_line_where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22
// Function brace style
33

44
fn lorem() {

tests/target/configs-item_brace_style-always_next_line.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22
// Item brace style
33

44
enum Foo {}
@@ -21,5 +21,7 @@ where
2121
mod tests
2222
{
2323
#[test]
24-
fn it_works() {}
24+
fn it_works()
25+
{
26+
}
2527
}

tests/target/configs-item_brace_style-prefer_same_line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22
// Item brace style
33

44
struct Lorem {

tests/target/configs-item_brace_style-same_line_where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22
// Item brace style
33

44
struct Lorem {

tests/target/fn-custom-6.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Block
2-
// rustfmt-fn_brace_style: PreferSameLine
2+
// rustfmt-brace_style: PreferSameLine
33
// Test different indents.
44

55
fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {

tests/target/fn-custom-7.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-normalize_comments: true
22
// rustfmt-indent_style: Block
33
// rustfmt-fn_args_density: Vertical
4-
// rustfmt-fn_brace_style: AlwaysNextLine
4+
// rustfmt-brace_style: AlwaysNextLine
55

66
// Case with only one variable.
77
fn foo(a: u8) -> u8
@@ -29,7 +29,8 @@ fn foo(
2929
bar()
3030
}
3131

32-
trait Test {
32+
trait Test
33+
{
3334
fn foo(a: u8)
3435
{
3536
}

tests/target/fn-custom-8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Block
2-
// rustfmt-fn_brace_style: PreferSameLine
2+
// rustfmt-brace_style: PreferSameLine
33
// Test different indents.
44

55
fn foo(a: Aaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbb) {

tests/target/indented-impl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// rustfmt-item_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22
mod x
33
{
44
struct X(i8);
55

66
impl Y for X
77
{
8-
fn y(self) -> () {
8+
fn y(self) -> ()
9+
{
910
println!("ok");
1011
}
1112
}

tests/target/item-brace-style-always-next-line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: AlwaysNextLine
1+
// rustfmt-brace_style: AlwaysNextLine
22

33
mod M
44
{

tests/target/item-brace-style-prefer-same-line.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: PreferSameLine
1+
// rustfmt-brace_style: PreferSameLine
22

33
mod M {
44
enum A {

tests/target/item-brace-style-same-line-where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-item_brace_style: SameLineWhere
1+
// rustfmt-brace_style: SameLineWhere
22

33
mod M {
44
enum A {

0 commit comments

Comments
 (0)