@@ -8,7 +8,7 @@ use crate::build_reduced_graph::{BuildReducedGraphVisitor, IsMacroExport};
88use crate :: resolve_imports:: ImportResolver ;
99use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX } ;
1010use rustc:: hir:: def:: { self , DefKind , NonMacroAttrKind } ;
11- use rustc:: hir:: map:: { self , DefCollector } ;
11+ use rustc:: hir:: map:: DefCollector ;
1212use rustc:: middle:: stability;
1313use rustc:: { ty, lint, span_bug} ;
1414use syntax:: ast:: { self , Ident } ;
@@ -32,14 +32,14 @@ use rustc_data_structures::sync::Lrc;
3232
3333type Res = def:: Res < ast:: NodeId > ;
3434
35+ // FIXME: Merge this with `ParentScope`.
3536#[ derive( Clone , Debug ) ]
3637pub struct InvocationData < ' a > {
37- def_index : DefIndex ,
3838 /// The module in which the macro was invoked.
39- crate module : Cell < Module < ' a > > ,
39+ crate module : Module < ' a > ,
4040 /// The legacy scope in which the macro was invoked.
4141 /// The invocation path is resolved in this scope.
42- crate parent_legacy_scope : Cell < LegacyScope < ' a > > ,
42+ crate parent_legacy_scope : LegacyScope < ' a > ,
4343 /// The legacy scope *produced* by expanding this macro invocation,
4444 /// includes all the macro_rules items, other invocations, etc generated by it.
4545 /// `None` if the macro is not expanded yet.
@@ -49,10 +49,9 @@ pub struct InvocationData<'a> {
4949impl < ' a > InvocationData < ' a > {
5050 pub fn root ( graph_root : Module < ' a > ) -> Self {
5151 InvocationData {
52- module : Cell :: new ( graph_root) ,
53- def_index : CRATE_DEF_INDEX ,
54- parent_legacy_scope : Cell :: new ( LegacyScope :: Empty ) ,
55- output_legacy_scope : Cell :: new ( Some ( LegacyScope :: Empty ) ) ,
52+ module : graph_root,
53+ parent_legacy_scope : LegacyScope :: Empty ,
54+ output_legacy_scope : Cell :: new ( None ) ,
5655 }
5756 }
5857}
@@ -74,9 +73,6 @@ pub struct LegacyBinding<'a> {
7473/// can potentially expand into macro definitions.
7574#[ derive( Copy , Clone , Debug ) ]
7675pub enum LegacyScope < ' a > {
77- /// Created when invocation data is allocated in the arena;
78- /// must be replaced with a proper scope later.
79- Uninitialized ,
8076 /// Empty "root" scope at the crate start containing no names.
8177 Empty ,
8278 /// The scope introduced by a `macro_rules!` macro definition.
@@ -139,11 +135,11 @@ impl<'a> base::Resolver for Resolver<'a> {
139135 fn get_module_scope ( & mut self , id : ast:: NodeId ) -> Mark {
140136 let mark = Mark :: fresh ( Mark :: root ( ) ) ;
141137 let module = self . module_map [ & self . definitions . local_def_id ( id) ] ;
138+ self . definitions . set_invocation_parent ( mark, module. def_id ( ) . unwrap ( ) . index ) ;
142139 self . invocations . insert ( mark, self . arenas . alloc_invocation_data ( InvocationData {
143- module : Cell :: new ( module) ,
144- def_index : module. def_id ( ) . unwrap ( ) . index ,
145- parent_legacy_scope : Cell :: new ( LegacyScope :: Empty ) ,
146- output_legacy_scope : Cell :: new ( Some ( LegacyScope :: Empty ) ) ,
140+ module,
141+ parent_legacy_scope : LegacyScope :: Empty ,
142+ output_legacy_scope : Cell :: new ( None ) ,
147143 } ) ) ;
148144 mark
149145 }
@@ -160,16 +156,20 @@ impl<'a> base::Resolver for Resolver<'a> {
160156
161157 fn visit_ast_fragment_with_placeholders ( & mut self , mark : Mark , fragment : & AstFragment ,
162158 derives : & [ Mark ] ) {
163- let invocation = self . invocations [ & mark] ;
164- self . collect_def_ids ( mark, invocation, fragment) ;
159+ fragment. visit_with ( & mut DefCollector :: new ( & mut self . definitions , mark) ) ;
165160
166- self . current_module = invocation. module . get ( ) ;
161+ let invocation = self . invocations [ & mark] ;
162+ self . current_module = invocation. module ;
167163 self . current_module . unresolved_invocations . borrow_mut ( ) . remove ( & mark) ;
168164 self . current_module . unresolved_invocations . borrow_mut ( ) . extend ( derives) ;
165+ let parent_def = self . definitions . invocation_parent ( mark) ;
166+ for & derive_invoc_id in derives {
167+ self . definitions . set_invocation_parent ( derive_invoc_id, parent_def) ;
168+ }
169169 self . invocations . extend ( derives. iter ( ) . map ( |& derive| ( derive, invocation) ) ) ;
170170 let mut visitor = BuildReducedGraphVisitor {
171171 resolver : self ,
172- current_legacy_scope : invocation. parent_legacy_scope . get ( ) ,
172+ current_legacy_scope : invocation. parent_legacy_scope ,
173173 expansion : mark,
174174 } ;
175175 fragment. visit_with ( & mut visitor) ;
@@ -259,9 +259,9 @@ impl<'a> Resolver<'a> {
259259 fn invoc_parent_scope ( & self , invoc_id : Mark , derives : Vec < ast:: Path > ) -> ParentScope < ' a > {
260260 let invoc = self . invocations [ & invoc_id] ;
261261 ParentScope {
262- module : invoc. module . get ( ) . nearest_item_scope ( ) ,
262+ module : invoc. module . nearest_item_scope ( ) ,
263263 expansion : invoc_id. parent ( ) ,
264- legacy : invoc. parent_legacy_scope . get ( ) ,
264+ legacy : invoc. parent_legacy_scope ,
265265 derives,
266266 }
267267 }
@@ -829,10 +829,9 @@ impl<'a> Resolver<'a> {
829829 binding. parent_legacy_scope
830830 ) ,
831831 LegacyScope :: Invocation ( invoc) => WhereToResolve :: MacroRules (
832- invoc. output_legacy_scope . get ( ) . unwrap_or ( invoc. parent_legacy_scope . get ( ) )
832+ invoc. output_legacy_scope . get ( ) . unwrap_or ( invoc. parent_legacy_scope )
833833 ) ,
834834 LegacyScope :: Empty => WhereToResolve :: Module ( parent_scope. module ) ,
835- LegacyScope :: Uninitialized => unreachable ! ( ) ,
836835 }
837836 WhereToResolve :: CrateRoot => match ns {
838837 TypeNS => {
@@ -1084,31 +1083,6 @@ impl<'a> Resolver<'a> {
10841083 }
10851084 }
10861085
1087- fn collect_def_ids ( & mut self ,
1088- mark : Mark ,
1089- invocation : & ' a InvocationData < ' a > ,
1090- fragment : & AstFragment ) {
1091- let Resolver { ref mut invocations, arenas, graph_root, .. } = * self ;
1092- let InvocationData { def_index, .. } = * invocation;
1093-
1094- let visit_macro_invoc = & mut |invoc : map:: MacroInvocationData | {
1095- invocations. entry ( invoc. mark ) . or_insert_with ( || {
1096- arenas. alloc_invocation_data ( InvocationData {
1097- def_index : invoc. def_index ,
1098- module : Cell :: new ( graph_root) ,
1099- parent_legacy_scope : Cell :: new ( LegacyScope :: Uninitialized ) ,
1100- output_legacy_scope : Cell :: new ( None ) ,
1101- } )
1102- } ) ;
1103- } ;
1104-
1105- let mut def_collector = DefCollector :: new ( & mut self . definitions , mark) ;
1106- def_collector. visit_macro_invoc = Some ( visit_macro_invoc) ;
1107- def_collector. with_parent ( def_index, |def_collector| {
1108- fragment. visit_with ( def_collector)
1109- } ) ;
1110- }
1111-
11121086 crate fn check_reserved_macro_name ( & mut self , ident : Ident , res : Res ) {
11131087 // Reserve some names that are not quite covered by the general check
11141088 // performed on `Resolver::builtin_attrs`.
0 commit comments