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

Reinstate single_match/single_match_else lints with comments #14420

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

samueltardieu
Copy link
Contributor

Commit efe3fe9 removed the ability for single_match and single_match_else to trigger if comments were present outside of the arms, as those comments would be lost while rewriting the match expression.

This reinstates the lint, but prevents the suggestion from being applied automatically in the presence of comments by using the MaybeIncorrect applicability. Also, a note is added to the lint message to warn the user about the need to preserve the comments if acting upon the suggestion.

changelog: [single_match, single_match_else]: reinstate lint when comments are inside the match but do not autofix the code

Fix #14418

@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
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 Mar 16, 2025
@samueltardieu
Copy link
Contributor Author

@GuillaumeGomez could you confirm that this is ok with running cargo clippy --fix on rustdoc's code? It should lint, but not autofix and swallow comments.

ojeda pushed a commit to ojeda/linux that referenced this pull request Mar 16, 2025
Extend the Result documentation by some guidelines and examples how
to handle Result error cases gracefully. And how to not handle them.

While at it fix one missing `Result` link in the existing documentation.

[ Moved links out-of-line for improved readability. Fixed `srctree`
  link. Sorted out-of-line links. Added newlines for consistency
  with other docs. Applied paragraph break suggestion. Reworded
  slightly the docs in a couple places. Added Markdown.

  In addition, added `#[allow(clippy::single_match)` for the first
  example. It cannot be an `expect` since due to a difference introduced
  in Rust 1.85.0 when there are comments in the arms of the `match`.
  Reported it upstream, but it was intended:

      rust-lang/rust-clippy#14418

  Perhaps Clippy will lint about it in the future, but without autofix:

      rust-lang/rust-clippy#14420

    - Miguel ]

Link: https://lore.kernel.org/rust-for-linux/CANiq72keOdXy0LFKk9SzYWwSjiD710v=hQO4xi+5E4xNALa6cA@mail.gmail.com/
Signed-off-by: Dirk Behme <[email protected]>
Reviewed-by: Fiona Behrens <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
@GuillaumeGomez
Copy link
Member

Looks good to me, thanks!

Commit efe3fe9 removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.
Copy link
Member

@Alexendoo Alexendoo left a comment

Choose a reason for hiding this comment

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

Thanks!

@Alexendoo Alexendoo added this pull request to the merge queue Mar 18, 2025
Merged via the queue into rust-lang:master with commit d443f38 Mar 18, 2025
11 checks passed
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.

clippy::single_match does not report if a comment is on top of an arm
4 participants