about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-01-28 19:48:39 +0100
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-01-29 10:02:03 +0100
commitad058cfafe584e1848276a05c2b7b5d3fcc965ff (patch)
treecaae2149f984c27216baeab6758e74ea820113b6
parent679f30e1aac510082b0fd3a2b5465321753aa7d1 (diff)
downloadrust-ad058cfafe584e1848276a05c2b7b5d3fcc965ff.tar.gz
rust-ad058cfafe584e1848276a05c2b7b5d3fcc965ff.zip
Make pattern visiting consistent
-rw-r--r--src/librustc/middle/region.rs6
-rw-r--r--src/librustc_typeck/check/generator_interior.rs8
2 files changed, 8 insertions, 6 deletions
diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs
index 66b3adb83c1..9d6b29adb04 100644
--- a/src/librustc/middle/region.rs
+++ b/src/librustc/middle/region.rs
@@ -467,9 +467,10 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
     }
 
     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 @@ impl<'tcx> ScopeTree {
 
     /// 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()
     }
diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs
index 781eeaef248..2e45e3b1f35 100644
--- a/src/librustc_typeck/check/generator_interior.rs
+++ b/src/librustc_typeck/check/generator_interior.rs
@@ -150,15 +150,15 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'gcx, '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) {