Skip to content
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

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Nov 26, 2024

Fixes #11846.

This PR has three commits:

  • The first commit adds an initializer-suggestions configuration to control suggestion applicability when initializers are present. The following are the options:
    • "none": do not suggest
    • "maybe-incorrect": suggest, but do not apply suggestions with --fix
    • "machine-applicable": suggest and apply suggestions with --fix
  • The second commit fixes suggestions to handle field attributes (problem noticed by @samueltardieu).
  • The third commit adds initializer-suggestions = "machine-applicable" to Clippy's clippy.toml and applies the suggestions. (Nothing seems to break.)

changelog: make inconsistent_struct_constructor "all fields are shorthand" requirement configurable

@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2024

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 26, 2024
Comment on lines 223 to 225
#[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 },
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @samueltardieu.

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@smoelius smoelius marked this pull request as draft November 27, 2024 01:19
@smoelius smoelius force-pushed the all-fields-are-shorthand branch from 1218259 to 6ddfaba Compare November 27, 2024 11:46
@smoelius smoelius marked this pull request as ready for review November 27, 2024 12:01
book/src/lint_configuration.md Outdated Show resolved Hide resolved
smoelius added a commit to smoelius/rust-clippy that referenced this pull request Nov 28, 2024
clippy_lints/src/inconsistent_struct_constructor.rs Outdated Show resolved Hide resolved
clippy_lints/src/inconsistent_struct_constructor.rs Outdated Show resolved Hide resolved
clippy_lints/src/inconsistent_struct_constructor.rs Outdated Show resolved Hide resolved
clippy_config/src/conf.rs Outdated Show resolved Hide resolved
///
/// [due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
#[lints(inconsistent_struct_constructor)]
initializer_suggestions: bool = false,
Copy link
Member

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

Copy link
Contributor Author

@smoelius smoelius Dec 9, 2024

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.

Copy link
Member

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

smoelius added a commit to smoelius/rust-clippy that referenced this pull request Dec 9, 2024
@smoelius
Copy link
Contributor Author

smoelius commented Dec 9, 2024

I think I have addressed all of the comments but this one: #13737 (comment)

Nits re my changes are welcome.

@bors
Copy link
Contributor

bors commented Dec 15, 2024

☔ The latest upstream changes (presumably 1dddeab) made this pull request unmergeable. Please resolve the merge conflicts.

@smoelius smoelius force-pushed the all-fields-are-shorthand branch from dbff5cd to 29c1dbd Compare December 15, 2024 18:19
smoelius added a commit to smoelius/rust-clippy that referenced this pull request Dec 15, 2024
smoelius added a commit to smoelius/rust-clippy that referenced this pull request Dec 15, 2024
Copy link
Member

@y21 y21 left a 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?

///
/// [due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
#[lints(inconsistent_struct_constructor)]
initializer_suggestions: bool = false,
Copy link
Member

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`
@smoelius smoelius force-pushed the all-fields-are-shorthand branch from eb83c07 to 8a38bcc Compare December 27, 2024 00:37
@smoelius
Copy link
Contributor Author

Oh, good. As of right now, I can access eb83c07.

Please let me know if there is anything else you would like changed, @y21. And thank you very much for the review. 🙏

Copy link
Member

@y21 y21 left a 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!

@y21 y21 added this pull request to the merge queue Dec 27, 2024
Merged via the queue into rust-lang:master with commit a8968e5 Dec 27, 2024
9 checks passed
@smoelius smoelius deleted the all-fields-are-shorthand branch December 27, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question re inconsistent_struct_constructor requirement
5 participants