Skip to content

Commit 3a5362c

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

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-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 Ok(context.snippet(field.span()).to_owned());
1953+
}
19501954

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

0 commit comments

Comments
 (0)