From ad058cfafe584e1848276a05c2b7b5d3fcc965ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 28 Jan 2018 19:48:39 +0100 Subject: [PATCH] Make pattern visiting consistent --- src/librustc/middle/region.rs | 6 ++++-- src/librustc_typeck/check/generator_interior.rs | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 66b3adb83c16..9d6b29adb049 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 781eeaef2482..2e45e3b1f352 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) {