@@ -40,11 +40,13 @@ struct LifetimeContext {
40
40
41
41
enum ScopeChain < ' a > {
42
42
ItemScope ( & ' a OptVec < ast:: Lifetime > ) ,
43
- FnScope ( ast:: NodeId , & ' a OptVec < ast:: Lifetime > , & ' a ScopeChain < ' a > ) ,
44
- BlockScope ( ast:: NodeId , & ' a ScopeChain < ' a > ) ,
43
+ FnScope ( ast:: NodeId , & ' a OptVec < ast:: Lifetime > , Scope < ' a > ) ,
44
+ BlockScope ( ast:: NodeId , Scope < ' a > ) ,
45
45
RootScope
46
46
}
47
47
48
+ type Scope < ' a > = & ' a ScopeChain < ' a > ;
49
+
48
50
pub fn krate ( sess : session:: Session , krate : & ast:: Crate )
49
51
-> @RefCell < NamedRegionMap > {
50
52
let mut ctxt = LifetimeContext {
@@ -56,10 +58,10 @@ pub fn krate(sess: session::Session, krate: &ast::Crate)
56
58
ctxt. named_region_map
57
59
}
58
60
59
- impl < ' a > Visitor < & ' a ScopeChain < ' a > > for LifetimeContext {
61
+ impl < ' a > Visitor < Scope < ' a > > for LifetimeContext {
60
62
fn visit_item ( & mut self ,
61
63
item : & ast:: Item ,
62
- _: & ' a ScopeChain < ' a > ) {
64
+ _: Scope < ' a > ) {
63
65
let scope = match item. node {
64
66
ast:: ItemFn ( ..) | // fn lifetimes get added in visit_fn below
65
67
ast:: ItemMod ( ..) |
@@ -84,7 +86,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
84
86
85
87
fn visit_fn ( & mut self , fk : & visit:: FnKind , fd : & ast:: FnDecl ,
86
88
b : & ast:: Block , s : Span , n : ast:: NodeId ,
87
- scope : & ' a ScopeChain < ' a > ) {
89
+ scope : Scope < ' a > ) {
88
90
match * fk {
89
91
visit:: FkItemFn ( _, generics, _, _) |
90
92
visit:: FkMethod ( _, generics, _) => {
@@ -101,7 +103,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
101
103
}
102
104
103
105
fn visit_ty ( & mut self , ty : & ast:: Ty ,
104
- scope : & ' a ScopeChain < ' a > ) {
106
+ scope : Scope < ' a > ) {
105
107
match ty. node {
106
108
ast:: TyClosure ( closure) => {
107
109
let scope1 = FnScope ( ty. id , & closure. lifetimes , scope) ;
@@ -125,7 +127,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
125
127
126
128
fn visit_ty_method ( & mut self ,
127
129
m : & ast:: TypeMethod ,
128
- scope : & ' a ScopeChain < ' a > ) {
130
+ scope : Scope < ' a > ) {
129
131
let scope1 = FnScope ( m. id , & m. generics . lifetimes , scope) ;
130
132
self . check_lifetime_names ( & m. generics . lifetimes ) ;
131
133
debug ! ( "pushing fn scope id={} due to ty_method" , m. id) ;
@@ -135,7 +137,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
135
137
136
138
fn visit_block ( & mut self ,
137
139
b : & ast:: Block ,
138
- scope : & ' a ScopeChain < ' a > ) {
140
+ scope : Scope < ' a > ) {
139
141
let scope1 = BlockScope ( b. id , scope) ;
140
142
debug ! ( "pushing block scope {}" , b. id) ;
141
143
visit:: walk_block ( self , b, & scope1) ;
@@ -144,7 +146,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
144
146
145
147
fn visit_lifetime_ref ( & mut self ,
146
148
lifetime_ref : & ast:: Lifetime ,
147
- scope : & ' a ScopeChain < ' a > ) {
149
+ scope : Scope < ' a > ) {
148
150
if lifetime_ref. name == special_idents:: statik. name {
149
151
self . insert_lifetime ( lifetime_ref, ast:: DefStaticRegion ) ;
150
152
return ;
@@ -156,7 +158,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
156
158
impl LifetimeContext {
157
159
fn resolve_lifetime_ref ( & self ,
158
160
lifetime_ref : & ast:: Lifetime ,
159
- scope : & ScopeChain ) {
161
+ scope : Scope ) {
160
162
// Walk up the scope chain, tracking the number of fn scopes
161
163
// that we pass through, until we find a lifetime with the
162
164
// given name or we run out of scopes. If we encounter a code
@@ -211,7 +213,7 @@ impl LifetimeContext {
211
213
fn resolve_free_lifetime_ref ( & self ,
212
214
scope_id : ast:: NodeId ,
213
215
lifetime_ref : & ast:: Lifetime ,
214
- scope : & ScopeChain ) {
216
+ scope : Scope ) {
215
217
// Walk up the scope chain, tracking the outermost free scope,
216
218
// until we encounter a scope that contains the named lifetime
217
219
// or we run out of scopes.
0 commit comments