Skip to content

match_same_arms: FP if arms have different comments #12044

Closed
@xFrednet

Description

@xFrednet

Summary

match_same_arms lints on two arms, if the comments are different.

Lint Name

match_same_arms

Reproducer

I tried this code:

#![warn(clippy::pedantic)]

fn main() {
    let test = Some(12);
    match test {
        Some(_) => {
            // My explaination for something cool
            println!("Test code");
        },
        None => {
            // My explaination
            println!("Test code");
        },
    }
}

Playground

I saw this happen:

warning: this match arm has an identical body to another arm
  --> src/main.rs:10:9
   |
10 |           None => {
   |           ^---
   |           |
   |  _________help: try merging the arm patterns: `None | Some(_)`
   | |
11 | |             // My explaination
12 | |             println!("Test code");
13 | |         },
   | |_________^
   |
   = help: or try changing either arm body
note: other arm here
  --> src/main.rs:6:9
   |
6  | /         Some(_) => {
7  | |             // My explaination for something cool
8  | |             println!("Test code");
9  | |         },
   | |_________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(clippy::pedantic)]
   |         ^^^^^^^^^^^^^^^^
   = note: `#[warn(clippy::match_same_arms)]` implied by `#[warn(clippy::pedantic)]`

I expected to see this happen:

No warning

Version

rustc 1.77.0-nightly (89e2160c4 2023-12-27)
binary: rustc
commit-hash: 89e2160c4ca5808657ed55392620ed1dbbce78d1
commit-date: 2023-12-27
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Additional Labels

These utils might be good to look at:

@rustbot label +good-first-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions