Make pattern visiting consistent

This commit is contained in:
John Kåre Alsaker 2018-01-28 19:48:39 +01:00
parent 679f30e1aa
commit ad058cfafe
2 changed files with 8 additions and 6 deletions

View file

@ -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()
}

View file

@ -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) {