Skip to content

Commit b6aa7b1

Browse files
committed
Fix clippy usages
1 parent 9fe2500 commit b6aa7b1

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

compiler/rustc_hir/src/hir.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,26 @@ pub enum MatchSource {
18951895
AwaitDesugar,
18961896
}
18971897

1898+
impl MatchSource {
1899+
pub fn equivalent(&self, other: &Self) -> bool {
1900+
use MatchSource::*;
1901+
match (self, other) {
1902+
(Normal, Normal)
1903+
| (IfLetGuardDesugar { .. }, IfLetGuardDesugar { .. })
1904+
| (WhileDesugar, WhileDesugar)
1905+
| (WhileLetDesugar { .. }, WhileLetDesugar { .. })
1906+
| (ForLoopDesugar, ForLoopDesugar)
1907+
| (TryDesugar, TryDesugar)
1908+
| (AwaitDesugar, AwaitDesugar) => true,
1909+
(
1910+
IfLetDesugar { contains_else_clause: l, .. },
1911+
IfLetDesugar { contains_else_clause: r, .. },
1912+
) => l == r,
1913+
_ => false,
1914+
}
1915+
}
1916+
}
1917+
18981918
impl MatchSource {
18991919
pub fn name(self) -> &'static str {
19001920
use MatchSource::*;

src/tools/clippy/clippy_lints/src/collapsible_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn check_arm<'tcx>(arm: &Arm<'tcx>, wild_outer_arm: &Arm<'tcx>, cx: &LateContext
8787
let mut used_visitor = LocalUsedVisitor::new(cx, binding_id);
8888
if match arm.guard {
8989
None => true,
90-
Some(Guard::If(expr) | Guard::IfLet(_, expr)) => !used_visitor.check_expr(expr),
90+
Some(Guard::If(expr) | Guard::IfLet(_, expr, _)) => !used_visitor.check_expr(expr),
9191
};
9292
// ...or anywhere in the inner match
9393
if !arms_inner.iter().any(|arm| used_visitor.check_arm(arm));

src/tools/clippy/clippy_lints/src/loops.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,9 @@ fn check_manual_flatten<'tcx>(
19941994
if_chain! {
19951995
if let Some(inner_expr) = inner_expr;
19961996
if let ExprKind::Match(
1997-
ref match_expr, ref match_arms, MatchSource::IfLetDesugar{ contains_else_clause: false }
1997+
ref match_expr,
1998+
ref match_arms,
1999+
MatchSource::IfLetDesugar { contains_else_clause: false, .. },
19982000
) = inner_expr.kind;
19992001
// Ensure match_expr in `if let` statement is the same as the pat from the for-loop
20002002
if let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind;

src/tools/clippy/clippy_utils/src/hir_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl HirEqInterExpr<'_, '_, '_> {
177177
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
178178
},
179179
(&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => {
180-
ls == rs
180+
ls.equivalent(rs)
181181
&& self.eq_expr(le, re)
182182
&& over(la, ra, |l, r| {
183183
self.eq_pat(&l.pat, &r.pat)

0 commit comments

Comments
 (0)