Skip to content

Commit 1c691e9

Browse files
Make sure we don't lose default struct value when formatting struct
1 parent b22856d commit 1c691e9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/tools/rustfmt/src/items.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,10 @@ pub(crate) fn rewrite_struct_field(
19471947
if contains_skip(&field.attrs) {
19481948
return Ok(context.snippet(field.span()).to_owned());
19491949
}
1950+
// FIXME(default_field_values): Implement formatting.
1951+
if field.default.is_some() {
1952+
return Err(RewriteError::SkipFormatting);
1953+
}
19501954

19511955
let type_annotation_spacing = type_annotation_spacing(context.config);
19521956
let prefix = rewrite_struct_field_prefix(context, field)?;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test for now that nightly default field values are left alone for now.
2+
3+
struct Foo {
4+
default_field: Spacing = /* uwu */ 0,
5+
}
6+
7+
a_macro!(
8+
struct Foo2 {
9+
default_field: Spacing = /* uwu */ 0,
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test for now that nightly default field values are left alone for now.
2+
3+
struct Foo {
4+
default_field: Spacing = /* uwu */ 0,
5+
}
6+
7+
a_macro!(
8+
struct Foo2 {
9+
default_field: Spacing = /* uwu */ 0,
10+
}
11+
);

0 commit comments

Comments
 (0)