Closed
Description
Summary
match_same_arms appears to use the expanded value of the cfg!
macro: when multiple match arms check for different cfgs, the lint reports that the arms are the same. Just because the values happen to be the same in this execution, doesn't mean they can be collapsed.
Lint Name
match_same_arms
Reproducer
I tried this code:
#[deny(clippy::match_same_arms)]
pub fn is_enabled(i: u32) -> bool {
match i {
0 => cfg!(enable_i_0),
1 => cfg!(enable_i_1),
2 => cfg!(enable_i_2),
_ => false,
}
}
I saw this happen:
error: this match arm has an identical body to another arm
--> src/lib.rs:6:9
|
6 | 1 => cfg!(enable_i_1),
| -^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `1 | 0`
|
= help: or try changing either arm body
note: other arm here
--> src/lib.rs:5:9
|
5 | 0 => cfg!(enable_i_0),
| ^^^^^^^^^^^^^^^^^^^^^
= 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/lib.rs:1:9
|
1 | #![deny(clippy::match_same_arms)]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
--> src/lib.rs:7:9
|
7 | 2 => cfg!(enable_i_2),
| -^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `2 | 0`
|
= help: or try changing either arm body
note: other arm here
--> src/lib.rs:5:9
|
5 | 0 => cfg!(enable_i_0),
| ^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/lib.rs:6:9
|
6 | 1 => cfg!(enable_i_1),
| -^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `1 | 2`
|
= help: or try changing either arm body
note: other arm here
--> src/lib.rs:7:9
|
7 | 2 => cfg!(enable_i_2),
| ^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
I expected to see this happen:
No error
Version
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: aarch64-apple-darwin
release: 1.64.0
LLVM version: 14.0.6
Additional Labels
No response