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.
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.
This problem should be resolved.
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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)
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.
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
… deprecated configurations (#14280) This PR does two things: - It renames `inconsistent_struct_constructor`'s configuration from `lint-inconsistent-struct-field-initializers` to `check-inconsistent-struct-field-initializers`. (I should have suggested `check-...` in [#13737](#13737 (comment)).) - It causes Clippy to no longer suggest deprecated configurations. (Previously, Clippy would suggest `cyclomatic-complexity-threshold`, for example.) r? @y21 changelog: Rename `lint-inconsistent-struct-field-initializers` to `check-inconsistent-struct-field-initializers` changelog: No longer suggest deprecated configurations
Fixes #11846.
This PR has three commits:
initializer-suggestionsconfiguration to control suggestion applicability when initializers are present. The following are the options:--fix--fixinitializer-suggestions = "machine-applicable"to Clippy'sclippy.tomland applies the suggestions. (Nothing seems to break.)changelog: make
inconsistent_struct_constructor"all fields are shorthand" requirement configurable