Skip to content

Commit 74a957e

Browse files
authored
Merge pull request #2357 from topecongiro/issue-2342
Put attributes and struct fields on different line by default
2 parents a7d1d1d + fbbaab8 commit 74a957e

File tree

18 files changed

+34
-150
lines changed

18 files changed

+34
-150
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- Remove `same_line_attributes` configuration option.
8+
59
## [0.3.4] 2017-12-23
610

711
### Added

Configurations.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -246,53 +246,6 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
246246
}
247247
```
248248

249-
250-
## `same_line_attributes`
251-
252-
Try to put attributes on the same line as fields and variants
253-
254-
- **Default value**: `true`
255-
- **Possible values**: `true`, `false`
256-
- **Stable**: No
257-
258-
#### `true` (default):
259-
260-
```rust
261-
struct Lorem {
262-
#[serde(rename = "Ipsum")] ipsum: usize,
263-
#[serde(rename = "Dolor")] dolor: usize,
264-
#[serde(rename = "Amet")] amet: usize,
265-
}
266-
267-
enum Lorem {
268-
#[serde(skip_serializing)] Ipsum,
269-
#[serde(skip_serializing)] Dolor,
270-
#[serde(skip_serializing)] Amet,
271-
}
272-
```
273-
274-
#### `false`:
275-
276-
```rust
277-
struct Lorem {
278-
#[serde(rename = "Ipsum")]
279-
ipsum: usize,
280-
#[serde(rename = "Dolor")]
281-
dolor: usize,
282-
#[serde(rename = "Amet")]
283-
amet: usize,
284-
}
285-
286-
enum Lorem {
287-
#[serde(skip_serializing)]
288-
Ipsum,
289-
#[serde(skip_serializing)]
290-
Dolor,
291-
#[serde(skip_serializing)]
292-
Amet,
293-
}
294-
```
295-
296249
## `use_small_heuristics`
297250

298251
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.

src/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,6 @@ create_config! {
648648
threshold.";
649649
remove_blank_lines_at_start_or_end_of_block: bool, true, false,
650650
"Remove blank lines at start or end of a block";
651-
same_line_attributes: bool, true, false,
652-
"Try to put attributes on the same line as fields and variants.";
653651
match_arm_blocks: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \
654652
the same line with the pattern of arms";
655653
force_multiline_blocks: bool, false, false,

src/file_lines.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ impl str::FromStr for FileLines {
204204
// For JSON decoding.
205205
#[derive(Clone, Debug, Deserialize)]
206206
struct JsonSpan {
207-
#[serde(deserialize_with = "deserialize_filename")] file: FileName,
207+
#[serde(deserialize_with = "deserialize_filename")]
208+
file: FileName,
208209
range: (usize, usize),
209210
}
210211

src/items.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,13 @@ impl<'a> FmtVisitor<'a> {
558558
}
559559
};
560560

561-
let attrs_extendable = attrs_str.is_empty()
562-
|| (context.config.same_line_attributes() && is_attributes_extendable(&attrs_str));
563561
combine_strs_with_missing_comments(
564562
&context,
565563
&attrs_str,
566564
&variant_body,
567565
span,
568566
shape,
569-
attrs_extendable,
567+
is_attributes_extendable(&attrs_str),
570568
)
571569
}
572570
}
@@ -1440,8 +1438,7 @@ pub fn rewrite_struct_field(
14401438
let prefix = rewrite_struct_field_prefix(context, field)?;
14411439

14421440
let attrs_str = field.attrs.rewrite(context, shape)?;
1443-
let attrs_extendable = attrs_str.is_empty()
1444-
|| (context.config.same_line_attributes() && is_attributes_extendable(&attrs_str));
1441+
let attrs_extendable = field.ident.is_none() && is_attributes_extendable(&attrs_str);
14451442
let missing_span = if field.attrs.is_empty() {
14461443
mk_sp(field.span.lo(), field.span.lo())
14471444
} else {

src/vertical.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ impl AlignedItem for ast::StructField {
5454
} else {
5555
mk_sp(self.attrs.last().unwrap().span.hi(), self.span.lo())
5656
};
57-
let attrs_extendable =
58-
context.config.same_line_attributes() && is_attributes_extendable(&attrs_str);
57+
let attrs_extendable = self.ident.is_none() && is_attributes_extendable(&attrs_str);
5958
rewrite_struct_field_prefix(context, self).and_then(|field_str| {
6059
combine_strs_with_missing_comments(
6160
context,

tests/source/configs/same_line_attributes/false.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/source/configs/same_line_attributes/true.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/source/issue-2342.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-max_width: 80
2+
3+
struct Foo {
4+
#[cfg(feature = "serde")] bytes: [[u8; 17]; 5], // Same size as signature::ED25519_PKCS8_V2_LEN
5+
}

tests/target/attrib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ impl Bar {
6262

6363
// #984
6464
struct Foo {
65-
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] foo: usize,
65+
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
66+
foo: usize,
6667
}
6768

6869
// #1668

0 commit comments

Comments
 (0)