@@ -19,6 +19,7 @@ use rustc::middle::cstore::CrateStore;
1919use rustc_metadata:: cstore:: LoadedMacro ;
2020
2121use std:: cell:: Cell ;
22+ use std:: ops:: { Deref , DerefMut } ;
2223use std:: ptr;
2324use rustc_data_structures:: sync:: Lrc ;
2425
@@ -115,7 +116,7 @@ impl<'a> Resolver<'a> {
115116 parent_prefix : & [ Segment ] ,
116117 nested : bool ,
117118 // The whole `use` item
118- parent_scope : ParentScope < ' a > ,
119+ parent_scope : & ParentScope < ' a > ,
119120 item : & Item ,
120121 vis : ty:: Visibility ,
121122 root_span : Span ,
@@ -249,7 +250,7 @@ impl<'a> Resolver<'a> {
249250 root_span,
250251 item. id ,
251252 vis,
252- parent_scope,
253+ parent_scope. clone ( ) ,
253254 ) ;
254255 }
255256 ast:: UseTreeKind :: Glob => {
@@ -266,7 +267,7 @@ impl<'a> Resolver<'a> {
266267 root_span,
267268 item. id ,
268269 vis,
269- parent_scope,
270+ parent_scope. clone ( ) ,
270271 ) ;
271272 }
272273 ast:: UseTreeKind :: Nested ( ref items) => {
@@ -297,7 +298,7 @@ impl<'a> Resolver<'a> {
297298 // This particular use tree
298299 tree, id, & prefix, true ,
299300 // The whole `use` item
300- parent_scope. clone ( ) , item, vis, root_span,
301+ parent_scope, item, vis, root_span,
301302 ) ;
302303 }
303304
@@ -327,14 +328,16 @@ impl<'a> Resolver<'a> {
327328 }
328329 }
329330 }
331+ }
330332
333+ impl < ' a > BuildReducedGraphVisitor < ' _ , ' a > {
331334 /// Constructs the reduced graph for one item.
332- fn build_reduced_graph_for_item ( & mut self , item : & Item , parent_scope : ParentScope < ' a > ) {
335+ fn build_reduced_graph_for_item ( & mut self , item : & Item , parent_scope : & ParentScope < ' a > ) {
333336 let parent = parent_scope. module ;
334337 let expansion = parent_scope. expansion ;
335338 let ident = item. ident . gensym_if_underscore ( ) ;
336339 let sp = item. span ;
337- let vis = self . resolve_visibility ( & item. vis ) ;
340+ let vis = self . resolve_visibility ( & item. vis , parent_scope ) ;
338341
339342 match item. node {
340343 ItemKind :: Use ( ref use_tree) => {
@@ -361,7 +364,9 @@ impl<'a> Resolver<'a> {
361364 } else if orig_name == Some ( kw:: SelfLower ) {
362365 self . graph_root
363366 } else {
364- let crate_id = self . crate_loader . process_extern_crate ( item, & self . definitions ) ;
367+ let crate_id = self . resolver . crate_loader . process_extern_crate (
368+ item, & self . resolver . definitions
369+ ) ;
365370 self . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
366371 } ;
367372
@@ -372,13 +377,13 @@ impl<'a> Resolver<'a> {
372377 }
373378 }
374379
375- let used = self . process_legacy_macro_imports ( item, module, & parent_scope) ;
380+ let used = self . process_legacy_macro_imports ( item, module, parent_scope) ;
376381 let binding =
377382 ( module, ty:: Visibility :: Public , sp, expansion) . to_name_binding ( self . arenas ) ;
378383 let directive = self . arenas . alloc_import_directive ( ImportDirective {
379384 root_id : item. id ,
380385 id : item. id ,
381- parent_scope,
386+ parent_scope : parent_scope . clone ( ) ,
382387 imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
383388 subclass : ImportDirectiveSubclass :: ExternCrate {
384389 source : orig_name,
@@ -395,7 +400,7 @@ impl<'a> Resolver<'a> {
395400 } ) ;
396401 self . potentially_unused_imports . push ( directive) ;
397402 let imported_binding = self . import ( binding, directive) ;
398- if ptr:: eq ( self . current_module , self . graph_root ) {
403+ if ptr:: eq ( parent , self . graph_root ) {
399404 if let Some ( entry) = self . extern_prelude . get ( & ident. modern ( ) ) {
400405 if expansion != ExpnId :: root ( ) && orig_name. is_some ( ) &&
401406 entry. extern_crate_item . is_none ( ) {
@@ -455,7 +460,7 @@ impl<'a> Resolver<'a> {
455460
456461 // Functions introducing procedural macros reserve a slot
457462 // in the macro namespace as well (see #52225).
458- self . define_macro ( item, expansion , & mut LegacyScope :: Empty ) ;
463+ self . define_macro ( item, parent_scope ) ;
459464 }
460465
461466 // These items live in the type namespace.
@@ -511,8 +516,8 @@ impl<'a> Resolver<'a> {
511516
512517 // Record field names for error reporting.
513518 let field_names = struct_def. fields ( ) . iter ( ) . filter_map ( |field| {
514- let field_vis = self . resolve_visibility ( & field. vis ) ;
515- if ctor_vis. is_at_least ( field_vis, & * self ) {
519+ let field_vis = self . resolve_visibility ( & field. vis , parent_scope ) ;
520+ if ctor_vis. is_at_least ( field_vis, & * self . resolver ) {
516521 ctor_vis = field_vis;
517522 }
518523 field. ident . map ( |ident| ident. name )
@@ -538,7 +543,7 @@ impl<'a> Resolver<'a> {
538543
539544 // Record field names for error reporting.
540545 let field_names = vdata. fields ( ) . iter ( ) . filter_map ( |field| {
541- self . resolve_visibility ( & field. vis ) ;
546+ self . resolve_visibility ( & field. vis , parent_scope ) ;
542547 field. ident . map ( |ident| ident. name )
543548 } ) . collect ( ) ;
544549 let item_def_id = self . definitions . local_def_id ( item. id ) ;
@@ -614,7 +619,13 @@ impl<'a> Resolver<'a> {
614619 ForeignItemKind :: Macro ( _) => unreachable ! ( ) ,
615620 } ;
616621 let parent = self . current_module ;
617- let vis = self . resolve_visibility ( & item. vis ) ;
622+ let parent_scope = & ParentScope {
623+ module : self . current_module ,
624+ expansion : self . expansion ,
625+ legacy : self . current_legacy_scope ,
626+ derives : Vec :: new ( ) ,
627+ } ;
628+ let vis = self . resolver . resolve_visibility ( & item. vis , parent_scope) ;
618629 self . define ( parent, item. ident , ns, ( res, vis, item. span , expn_id) ) ;
619630 }
620631
@@ -630,7 +641,9 @@ impl<'a> Resolver<'a> {
630641 self . current_module = module; // Descend into the block.
631642 }
632643 }
644+ }
633645
646+ impl < ' a > Resolver < ' a > {
634647 /// Builds the reduced graph for a single item in an external crate.
635648 fn build_reduced_graph_for_external_crate_res (
636649 & mut self ,
@@ -804,7 +817,9 @@ impl<'a> Resolver<'a> {
804817 self . session . struct_span_err ( span, & msg) . note ( note) . emit ( ) ;
805818 }
806819 }
820+ }
807821
822+ impl < ' a > BuildReducedGraphVisitor < ' _ , ' a > {
808823 /// Returns `true` if we should consider the underlying `extern crate` to be used.
809824 fn process_legacy_macro_imports ( & mut self , item : & Item , module : Module < ' a > ,
810825 parent_scope : & ParentScope < ' a > ) -> bool {
@@ -873,7 +888,7 @@ impl<'a> Resolver<'a> {
873888 ModuleOrUniformRoot :: Module ( module) ,
874889 ident,
875890 MacroNS ,
876- None ,
891+ parent_scope ,
877892 false ,
878893 ident. span ,
879894 ) ;
@@ -918,22 +933,36 @@ impl<'a> Resolver<'a> {
918933
919934pub struct BuildReducedGraphVisitor < ' a , ' b > {
920935 pub resolver : & ' a mut Resolver < ' b > ,
936+ pub current_module : Module < ' b > ,
921937 pub current_legacy_scope : LegacyScope < ' b > ,
922938 pub expansion : ExpnId ,
923939}
924940
941+ impl < ' b > Deref for BuildReducedGraphVisitor < ' _ , ' b > {
942+ type Target = Resolver < ' b > ;
943+ fn deref ( & self ) -> & Self :: Target {
944+ self . resolver
945+ }
946+ }
947+
948+ impl < ' b > DerefMut for BuildReducedGraphVisitor < ' _ , ' b > {
949+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
950+ self . resolver
951+ }
952+ }
953+
925954impl < ' a , ' b > BuildReducedGraphVisitor < ' a , ' b > {
926955 fn visit_invoc ( & mut self , id : ast:: NodeId ) -> & ' b InvocationData < ' b > {
927956 let invoc_id = id. placeholder_to_expn_id ( ) ;
928957
929- self . resolver . current_module . unresolved_invocations . borrow_mut ( ) . insert ( invoc_id) ;
958+ self . current_module . unresolved_invocations . borrow_mut ( ) . insert ( invoc_id) ;
930959
931- let invocation_data = self . resolver . arenas . alloc_invocation_data ( InvocationData {
932- module : self . resolver . current_module ,
960+ let invocation_data = self . arenas . alloc_invocation_data ( InvocationData {
961+ module : self . current_module ,
933962 parent_legacy_scope : self . current_legacy_scope ,
934963 output_legacy_scope : Cell :: new ( None ) ,
935964 } ) ;
936- let old_invocation_data = self . resolver . invocations . insert ( invoc_id, invocation_data) ;
965+ let old_invocation_data = self . invocations . insert ( invoc_id, invocation_data) ;
937966 assert ! ( old_invocation_data. is_none( ) , "invocation data is reset for an invocation" ) ;
938967
939968 invocation_data
@@ -959,30 +988,30 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
959988 method ! ( visit_ty: ast:: Ty , ast:: TyKind :: Mac , walk_ty) ;
960989
961990 fn visit_item ( & mut self , item : & ' a Item ) {
991+ let parent_scope = & ParentScope {
992+ module : self . current_module ,
993+ expansion : self . expansion ,
994+ legacy : self . current_legacy_scope ,
995+ derives : Vec :: new ( ) ,
996+ } ;
962997 let macro_use = match item. node {
963998 ItemKind :: MacroDef ( ..) => {
964- self . resolver . define_macro ( item, self . expansion , & mut self . current_legacy_scope ) ;
999+ self . current_legacy_scope = self . resolver . define_macro ( item, parent_scope ) ;
9651000 return
9661001 }
9671002 ItemKind :: Mac ( ..) => {
9681003 self . current_legacy_scope = LegacyScope :: Invocation ( self . visit_invoc ( item. id ) ) ;
9691004 return
9701005 }
971- ItemKind :: Mod ( ..) => self . resolver . contains_macro_use ( & item. attrs ) ,
1006+ ItemKind :: Mod ( ..) => self . contains_macro_use ( & item. attrs ) ,
9721007 _ => false ,
9731008 } ;
9741009
975- let orig_current_module = self . resolver . current_module ;
1010+ let orig_current_module = self . current_module ;
9761011 let orig_current_legacy_scope = self . current_legacy_scope ;
977- let parent_scope = ParentScope {
978- module : self . resolver . current_module ,
979- expansion : self . expansion ,
980- legacy : self . current_legacy_scope ,
981- derives : Vec :: new ( ) ,
982- } ;
983- self . resolver . build_reduced_graph_for_item ( item, parent_scope) ;
1012+ self . build_reduced_graph_for_item ( item, parent_scope) ;
9841013 visit:: walk_item ( self , item) ;
985- self . resolver . current_module = orig_current_module;
1014+ self . current_module = orig_current_module;
9861015 if !macro_use {
9871016 self . current_legacy_scope = orig_current_legacy_scope;
9881017 }
@@ -1002,34 +1031,34 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
10021031 return ;
10031032 }
10041033
1005- self . resolver . build_reduced_graph_for_foreign_item ( foreign_item, self . expansion ) ;
1034+ self . build_reduced_graph_for_foreign_item ( foreign_item, self . expansion ) ;
10061035 visit:: walk_foreign_item ( self , foreign_item) ;
10071036 }
10081037
10091038 fn visit_block ( & mut self , block : & ' a Block ) {
1010- let orig_current_module = self . resolver . current_module ;
1039+ let orig_current_module = self . current_module ;
10111040 let orig_current_legacy_scope = self . current_legacy_scope ;
1012- self . resolver . build_reduced_graph_for_block ( block, self . expansion ) ;
1041+ self . build_reduced_graph_for_block ( block, self . expansion ) ;
10131042 visit:: walk_block ( self , block) ;
1014- self . resolver . current_module = orig_current_module;
1043+ self . current_module = orig_current_module;
10151044 self . current_legacy_scope = orig_current_legacy_scope;
10161045 }
10171046
10181047 fn visit_trait_item ( & mut self , item : & ' a TraitItem ) {
1019- let parent = self . resolver . current_module ;
1048+ let parent = self . current_module ;
10201049
10211050 if let TraitItemKind :: Macro ( _) = item. node {
10221051 self . visit_invoc ( item. id ) ;
10231052 return
10241053 }
10251054
10261055 // Add the item to the trait info.
1027- let item_def_id = self . resolver . definitions . local_def_id ( item. id ) ;
1056+ let item_def_id = self . definitions . local_def_id ( item. id ) ;
10281057 let ( res, ns) = match item. node {
10291058 TraitItemKind :: Const ( ..) => ( Res :: Def ( DefKind :: AssocConst , item_def_id) , ValueNS ) ,
10301059 TraitItemKind :: Method ( ref sig, _) => {
10311060 if sig. decl . has_self ( ) {
1032- self . resolver . has_self . insert ( item_def_id) ;
1061+ self . has_self . insert ( item_def_id) ;
10331062 }
10341063 ( Res :: Def ( DefKind :: Method , item_def_id) , ValueNS )
10351064 }
@@ -1040,9 +1069,9 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
10401069 let vis = ty:: Visibility :: Public ;
10411070 self . resolver . define ( parent, item. ident , ns, ( res, vis, item. span , self . expansion ) ) ;
10421071
1043- self . resolver . current_module = parent. parent . unwrap ( ) ; // nearest normal ancestor
1072+ self . current_module = parent. parent . unwrap ( ) ; // nearest normal ancestor
10441073 visit:: walk_trait_item ( self , item) ;
1045- self . resolver . current_module = parent;
1074+ self . current_module = parent;
10461075 }
10471076
10481077 fn visit_token ( & mut self , t : Token ) {
@@ -1058,7 +1087,7 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
10581087 fn visit_attribute ( & mut self , attr : & ' a ast:: Attribute ) {
10591088 if !attr. is_sugared_doc && is_builtin_attr ( attr) {
10601089 let parent_scope = ParentScope {
1061- module : self . resolver . current_module . nearest_item_scope ( ) ,
1090+ module : self . current_module . nearest_item_scope ( ) ,
10621091 expansion : self . expansion ,
10631092 legacy : self . current_legacy_scope ,
10641093 // Let's hope discerning built-in attributes from derive helpers is not necessary
0 commit comments