Skip to content

Commit 8bcecff

Browse files
committed
Handle or patterns in single_match and single_match_else
1 parent 514824f commit 8bcecff

12 files changed

+419
-158
lines changed

clippy_lints/src/matches/match_wild_enum.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ enum CommonPrefixSearcher<'a> {
180180
}
181181
impl<'a> CommonPrefixSearcher<'a> {
182182
fn with_path(&mut self, path: &'a [PathSegment<'a>]) {
183-
match path {
184-
[path @ .., _] => self.with_prefix(path),
185-
[] => (),
183+
if let [path @ .., _] = path {
184+
self.with_prefix(path);
186185
}
187186
}
188187

clippy_lints/src/matches/overlapping_arms.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
3333
.filter_map(|arm| {
3434
if let Arm { pat, guard: None, .. } = *arm {
3535
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
36-
let lhs_const = match lhs {
37-
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?,
38-
None => {
39-
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40-
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
41-
},
36+
let lhs_const = if let Some(lhs) = lhs {
37+
constant(cx, cx.typeck_results(), lhs)?
38+
} else {
39+
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40+
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
4241
};
43-
let rhs_const = match rhs {
44-
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?,
45-
None => {
46-
let max_val_const = ty.numeric_max_val(cx.tcx)?;
47-
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
48-
},
42+
let rhs_const = if let Some(rhs) = rhs {
43+
constant(cx, cx.typeck_results(), rhs)?
44+
} else {
45+
let max_val_const = ty.numeric_max_val(cx.tcx)?;
46+
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
4947
};
5048
let lhs_val = lhs_const.int_value(cx, ty)?;
5149
let rhs_val = rhs_const.int_value(cx, ty)?;

0 commit comments

Comments
 (0)