diff --git a/Configurations.md b/Configurations.md index 45fda5beaee..c7fae70d1dd 100644 --- a/Configurations.md +++ b/Configurations.md @@ -296,9 +296,9 @@ let lorem = vec!["ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", " #### Lines longer than `array_width`: See [`indent_style`](#indent_style). -## `attributes_on_same_line_as_field` +## `same_line_attributes` -Try to put attributes on the same line as fields +Try to put attributes on the same line as fields and variants - **Default value**: `true` - **Possible values**: `true`, `false` @@ -311,6 +311,12 @@ struct Lorem { #[serde(rename = "Dolor")] dolor: usize, #[serde(rename = "Amet")] amet: usize, } + +enum Lorem { + #[serde(skip_serializing)] Ipsum, + #[serde(skip_serializing)] Dolor, + #[serde(skip_serializing)] Amet, +} ``` #### `false`: @@ -324,28 +330,7 @@ struct Lorem { #[serde(rename = "Amet")] amet: usize, } -``` -## `attributes_on_same_line_as_variant` - -Try to put attributes on the same line as variants - -- **Default value**: `true` -- **Possible values**: `true`, `false` - -#### `true` (default): - -```rust -enum Lorem { - #[serde(skip_serializing)] Ipsum, - #[serde(skip_serializing)] Dolor, - #[serde(skip_serializing)] Amet, -} -``` - -#### `false`: - -```rust enum Lorem { #[serde(skip_serializing)] Ipsum, @@ -356,6 +341,7 @@ enum Lorem { } ``` + ## `binop_separator` Where to put a binary operator when a binary expression goes multiline. diff --git a/src/config.rs b/src/config.rs index 2eae8867527..ebbe67dada5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -613,10 +613,8 @@ create_config! { threshold."; remove_blank_lines_at_start_or_end_of_block: bool, true, false, "Remove blank lines at start or end of a block"; - attributes_on_same_line_as_field: bool, true, false, - "Try to put attributes on the same line as fields."; - attributes_on_same_line_as_variant: bool, true, false, - "Try to put attributes on the same line as variants in enum declarations."; + same_line_attributes: bool, true, false, + "Try to put attributes on the same line as fields and variants."; multiline_closure_forces_block: bool, false, false, "Force multiline closure bodies to be wrapped in a block"; multiline_match_arm_forces_block: bool, false, false, diff --git a/src/items.rs b/src/items.rs index 9ddb314d717..c99a4db0fdf 100644 --- a/src/items.rs +++ b/src/items.rs @@ -567,8 +567,7 @@ impl<'a> FmtVisitor<'a> { }; let attrs_extendable = attrs_str.is_empty() - || (context.config.attributes_on_same_line_as_variant() - && is_attributes_extendable(&attrs_str)); + || (context.config.same_line_attributes() && is_attributes_extendable(&attrs_str)); combine_strs_with_missing_comments( &context, &attrs_str, @@ -1450,8 +1449,7 @@ pub fn rewrite_struct_field( let attrs_str = field.attrs.rewrite(context, shape)?; let attrs_extendable = attrs_str.is_empty() - || (context.config.attributes_on_same_line_as_field() - && is_attributes_extendable(&attrs_str)); + || (context.config.same_line_attributes() && is_attributes_extendable(&attrs_str)); let missing_span = if field.attrs.is_empty() { mk_sp(field.span.lo(), field.span.lo()) } else { diff --git a/src/vertical.rs b/src/vertical.rs index bb4bad7852e..d3b35677407 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -54,8 +54,8 @@ impl AlignedItem for ast::StructField { } else { mk_sp(self.attrs.last().unwrap().span.hi(), self.span.lo()) }; - let attrs_extendable = context.config.attributes_on_same_line_as_field() - && is_attributes_extendable(&attrs_str); + let attrs_extendable = + context.config.same_line_attributes() && is_attributes_extendable(&attrs_str); rewrite_struct_field_prefix(context, self).and_then(|field_str| { combine_strs_with_missing_comments( context, diff --git a/tests/source/configs-attributes_on_same_line_as_field-false.rs b/tests/source/configs-attributes_on_same_line_as_field-false.rs deleted file mode 100644 index 202d3e56aee..00000000000 --- a/tests/source/configs-attributes_on_same_line_as_field-false.rs +++ /dev/null @@ -1,17 +0,0 @@ -// rustfmt-attributes_on_same_line_as_field: false -// Option to place attributes on the same line as fields where possible - -struct Lorem { - #[ serde(rename = "Ipsum") ] - ipsum: usize, - #[ serde(rename = "Dolor") ] - dolor: usize, - #[ serde(rename = "Amet") ] - amet: usize, -} - -// #1943 -pub struct Bzip2 { - # [ serde (rename = "level") ] - level: i32 , -} diff --git a/tests/source/configs-attributes_on_same_line_as_field-true.rs b/tests/source/configs-attributes_on_same_line_as_field-true.rs deleted file mode 100644 index 3258c754e50..00000000000 --- a/tests/source/configs-attributes_on_same_line_as_field-true.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-attributes_on_same_line_as_field: true -// Option to place attributes on the same line as fields where possible - -struct Lorem { - #[ serde(rename = "Ipsum") ] - ipsum: usize, - #[ serde(rename = "Dolor") ] - dolor: usize, - #[ serde(rename = "Amet") ] - amet: usize, -} diff --git a/tests/source/configs-attributes_on_same_line_as_variant-false.rs b/tests/source/configs-attributes_on_same_line_as_variant-false.rs deleted file mode 100644 index d3456b7087c..00000000000 --- a/tests/source/configs-attributes_on_same_line_as_variant-false.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-attributes_on_same_line_as_variant: false -// Option to place attributes on the same line as variants where possible - -enum Lorem { - #[ serde(skip_serializing) ] - Ipsum, - #[ serde(skip_serializing) ] - Dolor, - #[ serde(skip_serializing) ] - Amet, -} diff --git a/tests/source/configs-attributes_on_same_line_as_variant-true.rs b/tests/source/configs-attributes_on_same_line_as_variant-true.rs deleted file mode 100644 index 0f7d98f200a..00000000000 --- a/tests/source/configs-attributes_on_same_line_as_variant-true.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-attributes_on_same_line_as_variant: true -// Option to place attributes on the same line as variants where possible - -enum Lorem { - #[ serde(skip_serializing) ] - Ipsum, - #[ serde(skip_serializing) ] - Dolor, - #[ serde(skip_serializing) ] - Amet, -} diff --git a/tests/target/configs-attributes_on_same_line_as_field-false.rs b/tests/target/configs-attributes_on_same_line_as_field-false.rs deleted file mode 100644 index 98c3c4b791c..00000000000 --- a/tests/target/configs-attributes_on_same_line_as_field-false.rs +++ /dev/null @@ -1,17 +0,0 @@ -// rustfmt-attributes_on_same_line_as_field: false -// Option to place attributes on the same line as fields where possible - -struct Lorem { - #[serde(rename = "Ipsum")] - ipsum: usize, - #[serde(rename = "Dolor")] - dolor: usize, - #[serde(rename = "Amet")] - amet: usize, -} - -// #1943 -pub struct Bzip2 { - #[serde(rename = "level")] - level: i32, -} diff --git a/tests/target/configs-attributes_on_same_line_as_field-true.rs b/tests/target/configs-attributes_on_same_line_as_field-true.rs deleted file mode 100644 index 3261fa24ea0..00000000000 --- a/tests/target/configs-attributes_on_same_line_as_field-true.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-attributes_on_same_line_as_field: true -// Option to place attributes on the same line as fields where possible - -struct Lorem { - #[serde(rename = "Ipsum")] ipsum: usize, - #[serde(rename = "Dolor")] dolor: usize, - #[serde(rename = "Amet")] amet: usize, -} diff --git a/tests/target/configs-attributes_on_same_line_as_variant-false.rs b/tests/target/configs-attributes_on_same_line_as_variant-false.rs deleted file mode 100644 index 3442a10915a..00000000000 --- a/tests/target/configs-attributes_on_same_line_as_variant-false.rs +++ /dev/null @@ -1,11 +0,0 @@ -// rustfmt-attributes_on_same_line_as_variant: false -// Option to place attributes on the same line as variants where possible - -enum Lorem { - #[serde(skip_serializing)] - Ipsum, - #[serde(skip_serializing)] - Dolor, - #[serde(skip_serializing)] - Amet, -} diff --git a/tests/target/configs-attributes_on_same_line_as_variant-true.rs b/tests/target/configs-attributes_on_same_line_as_variant-true.rs deleted file mode 100644 index 0bced842c75..00000000000 --- a/tests/target/configs-attributes_on_same_line_as_variant-true.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-attributes_on_same_line_as_variant: true -// Option to place attributes on the same line as variants where possible - -enum Lorem { - #[serde(skip_serializing)] Ipsum, - #[serde(skip_serializing)] Dolor, - #[serde(skip_serializing)] Amet, -}