]> git.lizzy.rs Git - rust.git/commitdiff
Make pattern visiting consistent
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sun, 28 Jan 2018 18:48:39 +0000 (19:48 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Mon, 29 Jan 2018 09:02:03 +0000 (10:02 +0100)
src/librustc/middle/region.rs
src/librustc_typeck/check/generator_interior.rs

index 66b3adb83c160a8a3f9b2da16c27e49cdce7f366..9d6b29adb0496a269f5102849bb5194ac301c6b0 100644 (file)
@@ -467,9 +467,10 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
     }
 
     fn visit_pat(&mut self, pat: &'tcx Pat) {
+        intravisit::walk_pat(self, pat);
+
         self.expr_and_pat_count += 1;
 
-        intravisit::walk_pat(self, pat);
     }
 
     fn visit_expr(&mut self, expr: &'tcx Expr) {
@@ -814,7 +815,8 @@ pub fn free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeReg
 
     /// Checks whether the given scope contains a `yield`. If so,
     /// returns `Some((span, expr_count))` with the span of a yield we found and
-    /// the number of expressions appearing before the `yield` in the body.
+    /// the number of expressions and patterns appearing before the `yield` in the body + 1.
+    /// If there a are multiple yields in a scope, the one with the highest number is returned.
     pub fn yield_in_scope(&self, scope: Scope) -> Option<(Span, usize)> {
         self.yield_in_scope.get(&scope).cloned()
     }
index 781eeaef2482cca189ca56db038b243f01a1f666..2e45e3b1f3521db331ef2d9fc537bbd6e0dba346 100644 (file)
@@ -150,15 +150,15 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
     }
 
     fn visit_pat(&mut self, pat: &'tcx Pat) {
+        intravisit::walk_pat(self, pat);
+
+        self.expr_count += 1;
+
         if let PatKind::Binding(..) = pat.node {
             let scope = self.region_scope_tree.var_scope(pat.hir_id.local_id);
             let ty = self.fcx.tables.borrow().pat_ty(pat);
             self.record(ty, Some(scope), None, pat.span);
         }
-
-        self.expr_count += 1;
-
-        intravisit::walk_pat(self, pat);
     }
 
     fn visit_expr(&mut self, expr: &'tcx Expr) {