about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamelid <camelidcamel@gmail.com>2020-12-25 10:49:03 -0800
committerNoah Lev <camelidcamel@gmail.com>2021-07-22 20:50:51 -0700
commitc3a03ae5b715cdfd4739a530c1b8adde0bb3360a (patch)
tree74067b4db544834c924cfdfac2f66ad243cf92f6
parente742158ef5483b9cd756b193402329af3d4ba177 (diff)
Combine two loops in `check_match`
Suggested by Nadrieril in
https://github.com/rust-lang/rust/pull/79051#discussion_r548778186.
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/check_match.rs11
1 files changed, 3 insertions, 8 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
index 22c07fbec68..6ceb0839a6c 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
@@ -113,7 +113,7 @@ impl PatCtxt<'_, '_> {
 }
 
 impl<'tcx> MatchVisitor<'_, 'tcx> {
-    fn check_patterns(&mut self, pat: &Pat<'_>) {
+    fn check_patterns(&self, pat: &Pat<'_>) {
         pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
         if !self.tcx.features().bindings_after_at {
             check_legality_of_bindings_in_at_patterns(self, pat);
@@ -154,18 +154,13 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
         arms: &'tcx [hir::Arm<'tcx>],
         source: hir::MatchSource,
     ) {
+        let mut cx = self.new_cx(scrut.hir_id);
+
         for arm in arms {
             // Check the arm for some things unrelated to exhaustiveness.
             self.check_patterns(&arm.pat);
             if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
                 self.check_patterns(pat);
-            }
-        }
-
-        let mut cx = self.new_cx(scrut.hir_id);
-
-        for arm in arms {
-            if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
                 let tpat = self.lower_pattern(&mut cx, pat, &mut false).0;
                 check_if_let_guard(&mut cx, &tpat, pat.hir_id);
             }