I ran into match_same_arms and was quite confused. I got ready to report a false positive, but then I found #860 and figured out that I just needed to use | in my pattern.
In #860 in the comments having clippy suggest of | is mentioned, but no issue seems to have been opened. So I'm doing so now :)
I'm pretty sure it has already been reported that what the lint means (ie. use |) is unclear but I can't find an issue for that. Maybe it was on IRC. The wiki does mention | with a link to the book but that's clearly not enough as people still get confused.
I'm currently revamping suggestions, I'll look into it.
Ok, I've open #1082. The error will now contain note: consider refactoring toblablah | foobar`` and the doc of the lint will be:
What it does: This lint checks for
matchwith identical arm bodies.Why is this bad? This is probably a copy & paste error. If arm bodies are the same on
purpose, you can factor them
using|.Known problems: Known problems: False positive possible with order dependent
match
(see issue #860).Example:
``` rust,ignore
match foo {
Bar => bar(),
Quz => quz(),
Baz => bar(), // <= oops
}This should probably be ``` rust,ignore match foo { Bar => bar(), Quz => quz(), Baz => baz(), // <= fixed }or if the original code was not a typo:
rust,ignore match foo { Bar | Baz => bar(), // <= shows the intent better Quz => quz(), }
Is that enough?
Looks great! :+1: Will the note in the error use the code that was found? That would make it usable by tools like rustfix.
To answer my own question: kinda. It uses the matched code but probably doesn't give it in a way that rustfix can use atm.
Yes, but the suggestion won't be applicable by rustfix. There is no clean way to signal that we need to remove one of the arm.
On the other hand I'm working on improving usability with rustfix in general.
Most helpful comment
Yes, but the suggestion won't be applicable by rustfix. There is no clean way to signal that we need to remove one of the arm.
On the other hand I'm working on improving usability with rustfix in general.