Skip to content

Commit ad058cf

Browse files
committed
Make pattern visiting consistent
1 parent 679f30e commit ad058cf

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/librustc/middle/region.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,10 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
467467
}
468468

469469
fn visit_pat(&mut self, pat: &'tcx Pat) {
470+
intravisit::walk_pat(self, pat);
471+
470472
self.expr_and_pat_count += 1;
471473

472-
intravisit::walk_pat(self, pat);
473474
}
474475

475476
fn visit_expr(&mut self, expr: &'tcx Expr) {
@@ -814,7 +815,8 @@ impl<'tcx> ScopeTree {
814815

815816
/// Checks whether the given scope contains a `yield`. If so,
816817
/// returns `Some((span, expr_count))` with the span of a yield we found and
817-
/// the number of expressions appearing before the `yield` in the body.
818+
/// the number of expressions and patterns appearing before the `yield` in the body + 1.
819+
/// If there a are multiple yields in a scope, the one with the highest number is returned.
818820
pub fn yield_in_scope(&self, scope: Scope) -> Option<(Span, usize)> {
819821
self.yield_in_scope.get(&scope).cloned()
820822
}

src/librustc_typeck/check/generator_interior.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'gcx, 'tcx> {
150150
}
151151

152152
fn visit_pat(&mut self, pat: &'tcx Pat) {
153+
intravisit::walk_pat(self, pat);
154+
155+
self.expr_count += 1;
156+
153157
if let PatKind::Binding(..) = pat.node {
154158
let scope = self.region_scope_tree.var_scope(pat.hir_id.local_id);
155159
let ty = self.fcx.tables.borrow().pat_ty(pat);
156160
self.record(ty, Some(scope), None, pat.span);
157161
}
158-
159-
self.expr_count += 1;
160-
161-
intravisit::walk_pat(self, pat);
162162
}
163163

164164
fn visit_expr(&mut self, expr: &'tcx Expr) {

0 commit comments

Comments
 (0)