-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive on match_same_arms #860
Comments
This lint also complained about this match *self {
SendError::InvalidData(msg) => msg,
SendError::Other(msg) => msg
} |
Why? match *self {
SendError::InvalidData(msg) | SendError::Other(msg) => msg
} |
Oh, right. I've never used |
Now this is really embarrassing, sorry. I wanted to report another clippy issue right now, but I'm going to sleep on it first. |
Eh, report away, false positives aren't a big deal. And in this case we should be suggesting the |. Documentation is fine for extended things, but suggestions should be prominent 😄 |
(when I say false positives I mean false positives when filing bugs, not clippy false positives ) |
Might also be worth mentioning matching on enums with named fields of the same name, e.g.: pub enum Test {
A { field: String },
B { field: String },
}
impl Test {
/// `match_same_arms` warning
fn field_bad(&self) -> &str {
match self {
Self::A { field } => field,
Self::B { field } => field,
}
}
/// no warning
fn field_good(&self) -> &str {
match self {
Self::A { field } | Self::B { field } => field,
}
}
} |
Example: Any kind of
xor
-like handling, e.g. letFoo
be one variant of an enum:This will trigger the lint, because the position of the arms is not taken into account.
@regexident suggested to only lint adjacent same arms. Another option would be to check if those arms are disjunct and can be reordered without changing semantics, but that is obviously much much harder to do in the general case.
The text was updated successfully, but these errors were encountered: