From 28ebec516015eb0b9cef05e5da0685a18620b105 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 26 Feb 2014 14:59:49 +0100 Subject: [PATCH] Introduce Scope<'a> shorthand for &'a ScopeChain<'a>. --- src/librustc/middle/resolve_lifetime.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 784b0cdab3d..90069cf899b 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -40,11 +40,13 @@ struct LifetimeContext { enum ScopeChain<'a> { ItemScope(&'a OptVec), - FnScope(ast::NodeId, &'a OptVec, &'a ScopeChain<'a>), - BlockScope(ast::NodeId, &'a ScopeChain<'a>), + FnScope(ast::NodeId, &'a OptVec, Scope<'a>), + BlockScope(ast::NodeId, Scope<'a>), RootScope } +type Scope<'a> = &'a ScopeChain<'a>; + pub fn krate(sess: session::Session, krate: &ast::Crate) -> @RefCell { let mut ctxt = LifetimeContext { @@ -56,10 +58,10 @@ pub fn krate(sess: session::Session, krate: &ast::Crate) ctxt.named_region_map } -impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext { +impl<'a> Visitor> for LifetimeContext { fn visit_item(&mut self, item: &ast::Item, - _: &'a ScopeChain<'a>) { + _: Scope<'a>) { let scope = match item.node { ast::ItemFn(..) | // fn lifetimes get added in visit_fn below ast::ItemMod(..) | @@ -84,7 +86,7 @@ fn visit_item(&mut self, fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl, b: &ast::Block, s: Span, n: ast::NodeId, - scope: &'a ScopeChain<'a>) { + scope: Scope<'a>) { match *fk { visit::FkItemFn(_, generics, _, _) | visit::FkMethod(_, generics, _) => { @@ -101,7 +103,7 @@ fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl, } fn visit_ty(&mut self, ty: &ast::Ty, - scope: &'a ScopeChain<'a>) { + scope: Scope<'a>) { match ty.node { ast::TyClosure(closure) => { let scope1 = FnScope(ty.id, &closure.lifetimes, scope); @@ -125,7 +127,7 @@ fn visit_ty(&mut self, ty: &ast::Ty, fn visit_ty_method(&mut self, m: &ast::TypeMethod, - scope: &'a ScopeChain<'a>) { + scope: Scope<'a>) { let scope1 = FnScope(m.id, &m.generics.lifetimes, scope); self.check_lifetime_names(&m.generics.lifetimes); debug!("pushing fn scope id={} due to ty_method", m.id); @@ -135,7 +137,7 @@ fn visit_ty_method(&mut self, fn visit_block(&mut self, b: &ast::Block, - scope: &'a ScopeChain<'a>) { + scope: Scope<'a>) { let scope1 = BlockScope(b.id, scope); debug!("pushing block scope {}", b.id); visit::walk_block(self, b, &scope1); @@ -144,7 +146,7 @@ fn visit_block(&mut self, fn visit_lifetime_ref(&mut self, lifetime_ref: &ast::Lifetime, - scope: &'a ScopeChain<'a>) { + scope: Scope<'a>) { if lifetime_ref.name == special_idents::statik.name { self.insert_lifetime(lifetime_ref, ast::DefStaticRegion); return; @@ -156,7 +158,7 @@ fn visit_lifetime_ref(&mut self, impl LifetimeContext { fn resolve_lifetime_ref(&self, lifetime_ref: &ast::Lifetime, - scope: &ScopeChain) { + scope: Scope) { // Walk up the scope chain, tracking the number of fn scopes // that we pass through, until we find a lifetime with the // given name or we run out of scopes. If we encounter a code @@ -211,7 +213,7 @@ fn resolve_lifetime_ref(&self, fn resolve_free_lifetime_ref(&self, scope_id: ast::NodeId, lifetime_ref: &ast::Lifetime, - scope: &ScopeChain) { + scope: Scope) { // Walk up the scope chain, tracking the outermost free scope, // until we encounter a scope that contains the named lifetime // or we run out of scopes. -- GitLab