@@ -19,18 +19,15 @@ pub(crate) fn collect_definitions(
19
19
fragment : & AstFragment ,
20
20
expansion : LocalExpnId ,
21
21
) {
22
- let InvocationParent { parent_def, impl_trait_context, in_attr } =
23
- resolver. invocation_parents [ & expansion] ;
24
- let mut visitor = DefCollector { resolver, parent_def, expansion, impl_trait_context, in_attr } ;
22
+ let invocation_parent = resolver. invocation_parents [ & expansion] ;
23
+ let mut visitor = DefCollector { resolver, expansion, invocation_parent } ;
25
24
fragment. visit_with ( & mut visitor) ;
26
25
}
27
26
28
27
/// Creates `DefId`s for nodes in the AST.
29
28
struct DefCollector < ' a , ' ra , ' tcx > {
30
29
resolver : & ' a mut Resolver < ' ra , ' tcx > ,
31
- parent_def : LocalDefId ,
32
- impl_trait_context : ImplTraitContext ,
33
- in_attr : bool ,
30
+ invocation_parent : InvocationParent ,
34
31
expansion : LocalExpnId ,
35
32
}
36
33
@@ -42,7 +39,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
42
39
def_kind : DefKind ,
43
40
span : Span ,
44
41
) -> LocalDefId {
45
- let parent_def = self . parent_def ;
42
+ let parent_def = self . invocation_parent . parent_def ;
46
43
debug ! (
47
44
"create_def(node_id={:?}, def_kind={:?}, parent_def={:?})" ,
48
45
node_id, def_kind, parent_def
@@ -60,19 +57,20 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
60
57
}
61
58
62
59
fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_def : LocalDefId , f : F ) {
63
- let orig_parent_def = mem:: replace ( & mut self . parent_def , parent_def) ;
60
+ let orig_parent_def = mem:: replace ( & mut self . invocation_parent . parent_def , parent_def) ;
64
61
f ( self ) ;
65
- self . parent_def = orig_parent_def;
62
+ self . invocation_parent . parent_def = orig_parent_def;
66
63
}
67
64
68
65
fn with_impl_trait < F : FnOnce ( & mut Self ) > (
69
66
& mut self ,
70
67
impl_trait_context : ImplTraitContext ,
71
68
f : F ,
72
69
) {
73
- let orig_itc = mem:: replace ( & mut self . impl_trait_context , impl_trait_context) ;
70
+ let orig_itc =
71
+ mem:: replace ( & mut self . invocation_parent . impl_trait_context , impl_trait_context) ;
74
72
f ( self ) ;
75
- self . impl_trait_context = orig_itc;
73
+ self . invocation_parent . impl_trait_context = orig_itc;
76
74
}
77
75
78
76
fn collect_field ( & mut self , field : & ' a FieldDef , index : Option < usize > ) {
@@ -96,14 +94,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
96
94
97
95
fn visit_macro_invoc ( & mut self , id : NodeId ) {
98
96
let id = id. placeholder_to_expn_id ( ) ;
99
- let old_parent = self . resolver . invocation_parents . insert (
100
- id,
101
- InvocationParent {
102
- parent_def : self . parent_def ,
103
- impl_trait_context : self . impl_trait_context ,
104
- in_attr : self . in_attr ,
105
- } ,
106
- ) ;
97
+ let old_parent = self . resolver . invocation_parents . insert ( id, self . invocation_parent ) ;
107
98
assert ! ( old_parent. is_none( ) , "parent `LocalDefId` is reset for an invocation" ) ;
108
99
}
109
100
}
@@ -367,7 +358,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
367
358
self . with_parent ( def, |this| visit:: walk_anon_const ( this, constant) ) ;
368
359
return ;
369
360
}
370
- _ => self . parent_def ,
361
+ _ => self . invocation_parent . parent_def ,
371
362
} ;
372
363
373
364
self . with_parent ( parent_def, |this| visit:: walk_expr ( this, expr) )
@@ -382,13 +373,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
382
373
// output or built artifacts, so replace them here...
383
374
// Perhaps we should instead format APITs more robustly.
384
375
let name = Symbol :: intern ( & pprust:: ty_to_string ( ty) . replace ( '\n' , " " ) ) ;
385
- let kind = match self . impl_trait_context {
376
+ let kind = match self . invocation_parent . impl_trait_context {
386
377
ImplTraitContext :: Universal => DefKind :: TyParam ,
387
378
ImplTraitContext :: Existential => DefKind :: OpaqueTy ,
388
379
ImplTraitContext :: InBinding => return visit:: walk_ty ( self , ty) ,
389
380
} ;
390
381
let id = self . create_def ( * id, Some ( name) , kind, ty. span ) ;
391
- match self . impl_trait_context {
382
+ match self . invocation_parent . impl_trait_context {
392
383
// Do not nest APIT, as we desugar them as `impl_trait: bounds`,
393
384
// so the `impl_trait` node is not a parent to `bounds`.
394
385
ImplTraitContext :: Universal => visit:: walk_ty ( self , ty) ,
@@ -459,9 +450,9 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
459
450
}
460
451
461
452
fn visit_attribute ( & mut self , attr : & ' a Attribute ) -> Self :: Result {
462
- let orig_in_attr = mem:: replace ( & mut self . in_attr , true ) ;
453
+ let orig_in_attr = mem:: replace ( & mut self . invocation_parent . in_attr , true ) ;
463
454
visit:: walk_attribute ( self , attr) ;
464
- self . in_attr = orig_in_attr;
455
+ self . invocation_parent . in_attr = orig_in_attr;
465
456
}
466
457
467
458
fn visit_inline_asm ( & mut self , asm : & ' a InlineAsm ) {
0 commit comments