Make sure we don't lose default struct value when formatting struct

This commit is contained in:
Michael Goulet 2024-12-22 22:09:59 +00:00
parent b22856d192
commit 68c46e13a2
4 changed files with 42 additions and 0 deletions

View File

@ -1944,6 +1944,11 @@ pub(crate) fn rewrite_struct_field(
shape: Shape,
lhs_max_width: usize,
) -> RewriteResult {
// FIXME(default_field_values): Implement formatting.
if field.default.is_some() {
return Err(RewriteError::Unknown);
}
if contains_skip(&field.attrs) {
return Ok(context.snippet(field.span()).to_owned());
}

View File

@ -144,6 +144,7 @@ impl Spanned for ast::GenericParam {
impl Spanned for ast::FieldDef {
fn span(&self) -> Span {
// FIXME(default_field_values): This needs to be adjusted.
span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi())
}
}

View File

@ -0,0 +1,18 @@
#![feature(default_struct_values)]
// Test for now that nightly default field values are left alone for now.
struct Foo {
default_field: Spacing = /* uwu */ 0,
}
struct Foo2 {
#[rustfmt::skip]
default_field: Spacing = /* uwu */ 0,
}
a_macro!(
struct Foo2 {
default_field: Spacing = /* uwu */ 0,
}
);

View File

@ -0,0 +1,18 @@
#![feature(default_struct_values)]
// Test for now that nightly default field values are left alone for now.
struct Foo {
default_field: Spacing = /* uwu */ 0,
}
struct Foo2 {
#[rustfmt::skip]
default_field: Spacing = /* uwu */ 0,
}
a_macro!(
struct Foo2 {
default_field: Spacing = /* uwu */ 0,
}
);