-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make inconsistent_struct_constructor
"all fields are shorthand" requirement configurable
#13737
Conversation
#[expect(clippy::bool_to_int_with_if)] // obfuscates the meaning | ||
expn_depth: if body.value.span.from_expansion() { 1 } else { 0 }, | ||
macro_unsafe_blocks: Vec::new(), | ||
expn_depth: if body.value.span.from_expansion() { 1 } else { 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.
The #[expect]
should have moved along with the field. That explains why you had to add your third commit, as you lost the attribute.
You should at the minimum re-add the attribute in the second commit and drop the third commit. But the attribute situation should be examined more closely.
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.
Thanks, @samueltardieu.
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 problem should be resolved.
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.
Do you mean manually, or automatically? Will attributes now move with the fields, or is this a bug that needs fixing? (I don't seem to find tests with this case that we now know is problematic)
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.
Do you mean manually, or automatically? Will attributes now move with the fields...
Yes, that is what I meant. (Thanks very much for noticing this, BTW.)
Here is the test I added: 0a91eaa#diff-377444135d6554122eb9b6c08b368b9d297fe68a76dfbcd4d9754ae5f85e1588R27-R41
Now, whether a similar problem exists for other lints, I can't say. I find it a little unfortunate that a field expression's span doesn't include its attributes. But there are no doubt arguments for doing it this way.
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.
Indeed, the new test is a great addition. Thanks!
1218259
to
6ddfaba
Compare
clippy_config/src/conf.rs
Outdated
/// | ||
/// [due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924 | ||
#[lints(inconsistent_struct_constructor)] | ||
initializer_suggestions: bool = false, |
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.
What do you think about naming this warn_inconsistent_struct_field_initializers
? IMO "suggestions" isn't so accurate anymore after the last change since whether this is enabled or not has no effect on the suggestion now
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.
What do you think about naming this
warn_inconsistent_struct_field_initializers
? IMO "suggestions" isn't so accurate anymore after the last change since whether this is enabled or not has no effect on the suggestion now
Could I suggest lint_inconsistent_struct_field_initializers
, or some other verb besides warn
?
camsteffen once pointed out to me that whether a lint actually warns is configurable.
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.
Yeah that works too. warn
seemed consistent with other similar named configs (there are two that start with warn_*
), but I agree with you that it's a bit of a misnomer when someone denies the lint
This comment is not yet addressed: rust-lang#13737 (comment)
I think I have addressed all of the comments but this one: #13737 (comment) Nits re my changes are welcome. |
☔ The latest upstream changes (presumably 1dddeab) made this pull request unmergeable. Please resolve the merge conflicts. |
dbff5cd
to
29c1dbd
Compare
This comment is not yet addressed: rust-lang#13737 (comment)
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.
LGTM with the configuration fixed, sorry it took a bit longer for me to get to this PR again. Can you also squash the commits?
clippy_config/src/conf.rs
Outdated
/// | ||
/// [due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924 | ||
#[lints(inconsistent_struct_constructor)] | ||
initializer_suggestions: bool = false, |
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.
Yeah that works too. warn
seemed consistent with other similar named configs (there are two that start with warn_*
), but I agree with you that it's a bit of a misnomer when someone denies the lint
Handle field attributes in suggestions Fix adjacent code Address review comments rust-lang#13737 (comment) Address all review comments but one This comment is not yet addressed: rust-lang#13737 (comment) `initializer_suggestions` -> `lint_inconsistent_struct_field_initializers`
eb83c07
to
8a38bcc
Compare
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.
Looks good to me, thanks!
Fixes #11846.
This PR has three commits:
initializer-suggestions
configuration to control suggestion applicability when initializers are present. The following are the options:--fix
--fix
initializer-suggestions = "machine-applicable"
to Clippy'sclippy.toml
and applies the suggestions. (Nothing seems to break.)changelog: make
inconsistent_struct_constructor
"all fields are shorthand" requirement configurable