- Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Summary
The match_same_arms
reports multiple arms that all contain todo!
but I think it should ignore this case. IDEs powered by rust-analyzer will pre-populate a match
statement with arms that contain todo!
and it is inconvenient that clippy immediately warms/errors on this. This is especially the case since warning on multiple todo!
is unlikely to address the intent of the lint.
According to https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms, the intent is to prevent this error:
This is probably a copy & paste error. If arm bodies are the same on purpose, you can factor them using |.
Multiple todo!
arms are unlikely a copy & paste error for anyone using rust-analyzer.
Lint Name
match_same_arms
Reproducer
I tried this code:
enum MyEnum { A, B, C, D, } fn example() { let e = MyEnum::A; match e { MyEnum::A => todo!(), MyEnum::B => todo!(), MyEnum::C => todo!(), MyEnum::D => todo!(), } }
I saw this happen:
error: this match arm has an identical body to another arm --> src/file.rs:21:9 | 21 | MyEnum::B => todo!(), | ---------^^^^^^^^^^^ | | | help: try merging the arm patterns: `MyEnum::B | MyEnum::A` | = note: `-D clippy::match-same-arms` implied by `-D clippy::pedantic` = help: or try changing either arm body note: other arm here --> src/file.rs:20:9 | 20 | MyEnum::A => todo!(), | ^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
Version
❯ rustc -Vv rustc 1.62.0 (a8314ef7d 2022-06-27) binary: rustc commit-hash: a8314ef7d0ec7b75c336af2c9857bfaf43002bfc commit-date: 2022-06-27 host: aarch64-apple-darwin release: 1.62.0 LLVM version: 14.0.5
Additional Labels
No response