Skip to content

Commit 2faabf5

Browse files
committed
Auto merge of rust-lang#80367 - camelid:check_match-combine-loop, r=Nadrieril
Combine two loops in `check_match` Suggested by Nadrieril in rust-lang#79051 (comment). Opening to get a perf run. Hopefully this code doesn't require everything in the first loop to be done before running the second! (It shouldn't though.) cc `@Nadrieril`
2 parents fd853c0 + c3a03ae commit 2faabf5

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl PatCtxt<'_, '_> {
112112
}
113113

114114
impl<'tcx> MatchVisitor<'_, 'tcx> {
115-
fn check_patterns(&mut self, pat: &Pat<'_>) {
115+
fn check_patterns(&self, pat: &Pat<'_>) {
116116
pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
117117
check_for_bindings_named_same_as_variants(self, pat);
118118
}
@@ -150,18 +150,13 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
150150
arms: &'tcx [hir::Arm<'tcx>],
151151
source: hir::MatchSource,
152152
) {
153+
let mut cx = self.new_cx(scrut.hir_id);
154+
153155
for arm in arms {
154156
// Check the arm for some things unrelated to exhaustiveness.
155157
self.check_patterns(&arm.pat);
156158
if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
157159
self.check_patterns(pat);
158-
}
159-
}
160-
161-
let mut cx = self.new_cx(scrut.hir_id);
162-
163-
for arm in arms {
164-
if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
165160
let tpat = self.lower_pattern(&mut cx, pat, &mut false).0;
166161
check_if_let_guard(&mut cx, &tpat, pat.hir_id);
167162
}

0 commit comments

Comments
 (0)