-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make sure we don't lose default struct value when formatting struct #134668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to change this to frame_support::construct_runtime!(
pub struct Test {
System: frame_system = 0,
SelfDomainId: pallet_domain_id = 1,
}
); If possible, could you also include the above snippet in the test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, the field span doesn't include the optional const. I just didn't actually re-test my test. I'm not going to include the snippet because it's identical in behavior to the snippet I included, though. I'll adjust the behavior though, and make sure to re-test it. |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also should go above the
contains_skip
since that would mess up:which I added a test for.