mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Fix manual_range_patterns case with one element at OR
This commit is contained in:
parent
ebcd6bc785
commit
494112e51f
3 changed files with 19 additions and 2 deletions
|
@ -77,9 +77,10 @@ impl Num {
|
|||
impl LateLintPass<'_> for ManualRangePatterns {
|
||||
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &'_ rustc_hir::Pat<'_>) {
|
||||
// a pattern like 1 | 2 seems fine, lint if there are at least 3 alternatives
|
||||
// or at least one range
|
||||
// or more then one range (exclude triggering on stylistic using OR with one element
|
||||
// like described https://github.com/rust-lang/rust-clippy/issues/11825)
|
||||
if let PatKind::Or(pats) = pat.kind
|
||||
&& (pats.len() >= 3 || pats.iter().any(|p| matches!(p.kind, PatKind::Range(..))))
|
||||
&& (pats.len() >= 3 || (pats.len() > 1 && pats.iter().any(|p| matches!(p.kind, PatKind::Range(..)))))
|
||||
&& !in_external_macro(cx.sess(), pat.span)
|
||||
{
|
||||
let mut min = Num::dummy(i128::MAX);
|
||||
|
|
|
@ -45,4 +45,12 @@ fn main() {
|
|||
};
|
||||
}
|
||||
mac!(f);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let _ = match f {
|
||||
| 2..=15 => 4,
|
||||
| 241..=254 => 5,
|
||||
| 255 => 6,
|
||||
| _ => 7,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,4 +45,12 @@ fn main() {
|
|||
};
|
||||
}
|
||||
mac!(f);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let _ = match f {
|
||||
| 2..=15 => 4,
|
||||
| 241..=254 => 5,
|
||||
| 255 => 6,
|
||||
| _ => 7,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue