-
Notifications
You must be signed in to change notification settings - Fork 1.7k
clippy::single_match
does not report if a comment is on top of an arm
#14418
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
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-negative
Issue: The lint should have been triggered on code, but wasn't
Comments
49 tasks
This (non-lint) was introduced in #13765. Maybe it would be a good idea to lint, but mark the suggestion as |
I see, thanks for the quick reply! Yeah, if there are comments, then someone should manually inspect it and transform the comments as needed. |
ojeda
pushed a commit
to ojeda/linux
that referenced
this issue
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]>
github-merge-queue bot
pushed a commit
that referenced
this issue
Mar 18, 2025
) 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-negative
Issue: The lint should have been triggered on code, but wasn't
Summary
Starting with Rust 1.85.0,
clippy::single_match
apparently does not get emitted when there is a comment on top of an arm.Is this intended?
Lint Name
clippy::single_match
Reproducer
I tried this code:
I expected to see this happen: Lint emitted as usual, e.g.
Instead, this happened: No lint emitted.
If one removes the
// X
line, or if one downgrades to 1.84.0, then the lint does get emitted.Reproducer: https://godbolt.org/z/K7zoonG8j (Compiler Explorer supports Clippy now! :)
Version
The text was updated successfully, but these errors were encountered: