Open frewsxcv opened 11 months ago
This lint already exists: redundant_guards
Your example code has this warning:
warning: redundant guard
--> src/main.rs:4:14
|
4 | y if y == 100 => {},
| ^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
= note: `#[warn(clippy::redundant_guards)]` on by default
help: try
|
4 - y if y == 100 => {},
4 + 100 => {},
This didn't cause a warning for me when using bitflags:
And yes I have clippy lints turned on in my VSCode
Looks like a false negative then.
From a quick glance, it looks like clippy doesn't consider a path to a const (GeomType::POINT
) as an expression that can be a pattern, even though it really could be.
Smaller repro that doesn't emit any warnings, without the bitflags
dep:
const X: i32 = 1;
match 1 {
x if x == X => {}
_ => {}
}
Note that not all consts can be patterns and the precise semantics are being worked out. https://github.com/rust-lang/lang-team/issues/220 Though in this case I would be surprised if anything stopped a const like this from working as a pattern.
What it does
Prefer matching on the value directly instead of using a guard with equality
Advantage
No response
Drawbacks
No response
Example
Could be written as: