Skip to content

match_same_arms false positive with associated constants #16698

@max-heller

Description

@max-heller

Summary

match_same_arms appears to consider two arms the same if their bodies are references to different associated constants that happen to evaluate the same.

Lint Name

match_same_arms

Reproducer

I tried this code:

#![warn(clippy::match_same_arms)]

fn main() {
    trait Foo {
        const X: u8;
    }
    impl Foo for u8 {
        const X: u8 = 2;
    }
    impl Foo for i8 {
        const X: u8 = 2;
    }
    match true {
        false => u8::X,
        true => i8::X,
    };
}

I saw this happen:

warning: these match arms have identical bodies
  --> test.rs:14:9
   |
14 |         false => u8::X,
   |         ^^^^^^^^^^^^^^
15 |         true => i8::X,
   |         ^^^^^^^^^^^^^
   |
   = help: if this is unintentional make the arms return different values
   = 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
  --> test.rs:1:9
   |
 1 | #![warn(clippy::match_same_arms)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^
help: otherwise merge the patterns into a single arm
   |
14 -         false => u8::X,
15 -         true => i8::X,
14 +         false | true => i8::X,
   |

I expected to see this happen: no warning

Version

rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: aarch64-apple-darwin
release: 1.94.0
LLVM version: 21.1.8

This appears to be a regression between 1.91.1 and 1.92.0

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions