mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Auto merge of #13311 - alex-semenyuk:fix_manual_range_patterns, r=Manishearth
Fix manual_range_patterns case with one element at OR Close #11825 As mentioned #11825 `OR` can be used for stylistic purposes with one element, we can filter this case from triggering lint changelog: [`manual_range_patterns`]: not trigger when `OR` has only one element
This commit is contained in:
commit
f194e684b1
3 changed files with 19 additions and 2 deletions
|
@ -77,9 +77,10 @@ impl Num {
|
||||||
impl LateLintPass<'_> for ManualRangePatterns {
|
impl LateLintPass<'_> for ManualRangePatterns {
|
||||||
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &'_ rustc_hir::Pat<'_>) {
|
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
|
// 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
|
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)
|
&& !in_external_macro(cx.sess(), pat.span)
|
||||||
{
|
{
|
||||||
let mut min = Num::dummy(i128::MAX);
|
let mut min = Num::dummy(i128::MAX);
|
||||||
|
|
|
@ -45,4 +45,12 @@ fn main() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
mac!(f);
|
mac!(f);
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let _ = match f {
|
||||||
|
| 2..=15 => 4,
|
||||||
|
| 241..=254 => 5,
|
||||||
|
| 255 => 6,
|
||||||
|
| _ => 7,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,12 @@ fn main() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
mac!(f);
|
mac!(f);
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let _ = match f {
|
||||||
|
| 2..=15 => 4,
|
||||||
|
| 241..=254 => 5,
|
||||||
|
| 255 => 6,
|
||||||
|
| _ => 7,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue