Merge attributes_on_same_line_as_field and attributes_on_same_line_as_variant into same_line_attributes

This commit is contained in:
Nick Cameron 2017-11-24 14:29:44 +13:00
parent d00c60df5c
commit 20805acf42
12 changed files with 15 additions and 127 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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 {

View File

@ -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,

View File

@ -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 ,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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,
}