8000 `clippy::single_match` does not report if a comment is on top of an arm · Issue #14418 · rust-lang/rust-clippy · GitHub
[go: up one dir, main page]

Skip to content
clippy::single_match does not report if a comment is on top of an arm #14418
@ojeda

Description

@ojeda

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:

fn _f() {
    match Vec::<i32>::new().try_reserve(42) {
        Err(_) => (),
        // X
        Ok(()) => (),
    }
}

I expected to see this happen: Lint emitted as usual, e.g.

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
 --> <source>:2:5
  |
2 | /     match Vec::<i32>::new().try_reserve(42) {
3 | |         Err(_) => (),
4 | |         Ok(()) => (),
5 | |     }
  | |_____^ help: try: `if let Err(_) = Vec::<i32>::new().try_reserve(42) { () }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
  = note: `#[warn(clippy::single_match)]` on by default

warning: 1 warning emitted

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

rustc 1.85.0 (4d91de4e4 2025-02-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0