@@ -66,21 +66,8 @@ pub enum LegacyScope<'a> {
66
66
Binding ( & ' a LegacyBinding < ' a > ) ,
67
67
}
68
68
69
- impl < ' a > LegacyScope < ' a > {
70
- fn simplify_expansion ( mut invoc : & ' a InvocationData < ' a > ) -> Self {
71
- while let LegacyScope :: Invocation ( _) = invoc. expansion . get ( ) {
72
- match invoc. legacy_scope . get ( ) {
73
- LegacyScope :: Expansion ( new_invoc) => invoc = new_invoc,
74
- LegacyScope :: Binding ( _) => break ,
75
- scope @ _ => return scope,
76
- }
77
- }
78
- LegacyScope :: Expansion ( invoc)
79
- }
80
- }
81
-
82
69
pub struct LegacyBinding < ' a > {
83
- pub parent : LegacyScope < ' a > ,
70
+ pub parent : Cell < LegacyScope < ' a > > ,
84
71
pub name : ast:: Name ,
85
72
ext : Rc < SyntaxExtension > ,
86
73
pub span : Span ,
@@ -157,7 +144,7 @@ impl<'a> base::Resolver for Resolver<'a> {
157
144
158
145
let invocation = self . invocations [ & scope] ;
159
146
let binding = self . arenas . alloc_legacy_binding ( LegacyBinding {
160
- parent : invocation. legacy_scope . get ( ) ,
147
+ parent : Cell :: new ( invocation. legacy_scope . get ( ) ) ,
161
148
name : def. ident . name ,
162
149
ext : Rc :: new ( macro_rules:: compile ( & self . session . parse_sess , & def) ) ,
163
150
span : def. span ,
@@ -228,12 +215,8 @@ impl<'a> base::Resolver for Resolver<'a> {
228
215
let name = path. segments [ 0 ] . identifier . name ;
229
216
230
217
let invocation = self . invocations [ & scope] ;
231
- if let LegacyScope :: Expansion ( parent) = invocation. legacy_scope . get ( ) {
232
- invocation. legacy_scope . set ( LegacyScope :: simplify_expansion ( parent) ) ;
233
- }
234
-
235
218
self . current_module = invocation. module . get ( ) ;
236
- let result = match self . resolve_legacy_scope ( invocation. legacy_scope . get ( ) , name, false ) {
219
+ let result = match self . resolve_legacy_scope ( & invocation. legacy_scope , name, false ) {
237
220
Some ( MacroBinding :: Legacy ( binding) ) => Ok ( binding. ext . clone ( ) ) ,
238
221
Some ( MacroBinding :: Modern ( binding) ) => Ok ( self . get_macro ( binding) ) ,
239
222
None => match self . resolve_in_item_lexical_scope ( name, MacroNS , None ) {
@@ -299,30 +282,34 @@ impl<'a> Resolver<'a> {
299
282
}
300
283
301
284
pub fn resolve_legacy_scope ( & mut self ,
302
- mut scope : LegacyScope < ' a > ,
285
+ mut scope : & ' a Cell < LegacyScope < ' a > > ,
303
286
name : Name ,
304
287
record_used : bool )
305
288
-> Option < MacroBinding < ' a > > {
306
289
let mut possible_time_travel = None ;
307
290
let mut relative_depth: u32 = 0 ;
308
291
let mut binding = None ;
309
292
loop {
310
- scope = match scope {
293
+ match scope. get ( ) {
311
294
LegacyScope :: Empty => break ,
312
295
LegacyScope :: Expansion ( invocation) => {
313
- if let LegacyScope :: Empty = invocation. expansion . get ( ) {
314
- if possible_time_travel. is_none ( ) {
315
- possible_time_travel = Some ( scope) ;
296
+ match invocation. expansion . get ( ) {
297
+ LegacyScope :: Invocation ( _) => scope. set ( invocation. legacy_scope . get ( ) ) ,
298
+ LegacyScope :: Empty => {
299
+ if possible_time_travel. is_none ( ) {
300
+ possible_time_travel = Some ( scope) ;
301
+ }
302
+ scope = & invocation. legacy_scope ;
303
+ }
304
+ _ => {
305
+ relative_depth += 1 ;
306
+ scope = & invocation. expansion ;
316
307
}
317
- invocation. legacy_scope . get ( )
318
- } else {
319
- relative_depth += 1 ;
320
- invocation. expansion . get ( )
321
308
}
322
309
}
323
310
LegacyScope :: Invocation ( invocation) => {
324
311
relative_depth = relative_depth. saturating_sub ( 1 ) ;
325
- invocation. legacy_scope . get ( )
312
+ scope = & invocation. legacy_scope ;
326
313
}
327
314
LegacyScope :: Binding ( potential_binding) => {
328
315
if potential_binding. name == name {
@@ -332,7 +319,7 @@ impl<'a> Resolver<'a> {
332
319
binding = Some ( potential_binding) ;
333
320
break
334
321
}
335
- potential_binding. parent
322
+ scope = & potential_binding. parent ;
336
323
}
337
324
} ;
338
325
}
@@ -358,7 +345,7 @@ impl<'a> Resolver<'a> {
358
345
pub fn finalize_current_module_macro_resolutions ( & mut self ) {
359
346
let module = self . current_module ;
360
347
for & ( mark, name, span) in module. legacy_macro_resolutions . borrow ( ) . iter ( ) {
361
- let legacy_scope = self . invocations [ & mark] . legacy_scope . get ( ) ;
348
+ let legacy_scope = & self . invocations [ & mark] . legacy_scope ;
362
349
let legacy_resolution = self . resolve_legacy_scope ( legacy_scope, name, true ) ;
363
350
let resolution = self . resolve_in_item_lexical_scope ( name, MacroNS , Some ( span) ) ;
364
351
let ( legacy_resolution, resolution) = match ( legacy_resolution, resolution) {
0 commit comments