@@ -332,7 +332,8 @@ impl<'a> Resolver<'a> {
332
332
333
333
impl < ' a > BuildReducedGraphVisitor < ' _ , ' a > {
334
334
/// Constructs the reduced graph for one item.
335
- 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 ) {
336
+ let parent_scope = & self . parent_scope . clone ( ) ;
336
337
let parent = parent_scope. module ;
337
338
let expansion = parent_scope. expansion ;
338
339
let ident = item. ident . gensym_if_underscore ( ) ;
@@ -439,7 +440,7 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
439
440
self . module_map . insert ( def_id, module) ;
440
441
441
442
// Descend into the module.
442
- self . current_module = module;
443
+ self . parent_scope . module = module;
443
444
}
444
445
445
446
// Handled in `rustc_metadata::{native_libs,link_args}`
@@ -563,7 +564,7 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
563
564
expansion,
564
565
item. span ) ;
565
566
self . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
566
- self . current_module = module;
567
+ self . parent_scope . module = module;
567
568
}
568
569
569
570
ItemKind :: MacroDef ( ..) | ItemKind :: Mac ( _) => unreachable ! ( ) ,
@@ -605,7 +606,7 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
605
606
}
606
607
607
608
/// Constructs the reduced graph for one foreign item.
608
- fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem , expn_id : ExpnId ) {
609
+ fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem ) {
609
610
let ( res, ns) = match item. node {
610
611
ForeignItemKind :: Fn ( ..) => {
611
612
( Res :: Def ( DefKind :: Fn , self . definitions . local_def_id ( item. id ) ) , ValueNS )
@@ -618,27 +619,23 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
618
619
}
619
620
ForeignItemKind :: Macro ( _) => unreachable ! ( ) ,
620
621
} ;
621
- let parent = self . current_module ;
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) ;
629
- self . define ( parent, item. ident , ns, ( res, vis, item. span , expn_id) ) ;
622
+ let parent = self . parent_scope . module ;
623
+ let expansion = self . parent_scope . expansion ;
624
+ let vis = self . resolver . resolve_visibility ( & item. vis , & self . parent_scope ) ;
625
+ self . define ( parent, item. ident , ns, ( res, vis, item. span , expansion) ) ;
630
626
}
631
627
632
- fn build_reduced_graph_for_block ( & mut self , block : & Block , expn_id : ExpnId ) {
633
- let parent = self . current_module ;
628
+ fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
629
+ let parent = self . parent_scope . module ;
630
+ let expansion = self . parent_scope . expansion ;
634
631
if self . block_needs_anonymous_module ( block) {
635
632
let module = self . new_module ( parent,
636
633
ModuleKind :: Block ( block. id ) ,
637
634
parent. normal_ancestor_id ,
638
- expn_id ,
635
+ expansion ,
639
636
block. span ) ;
640
637
self . block_map . insert ( block. id , module) ;
641
- self . current_module = module; // Descend into the block.
638
+ self . parent_scope . module = module; // Descend into the block.
642
639
}
643
640
}
644
641
}
@@ -827,7 +824,7 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
827
824
let mut single_imports = Vec :: new ( ) ;
828
825
for attr in & item. attrs {
829
826
if attr. check_name ( sym:: macro_use) {
830
- if self . current_module . parent . is_some ( ) {
827
+ if self . parent_scope . module . parent . is_some ( ) {
831
828
span_err ! ( self . session, item. span, E0468 ,
832
829
"an `extern crate` loading macros must be at the crate root" ) ;
833
830
}
@@ -933,9 +930,7 @@ impl<'a> BuildReducedGraphVisitor<'_, 'a> {
933
930
934
931
pub struct BuildReducedGraphVisitor < ' a , ' b > {
935
932
pub resolver : & ' a mut Resolver < ' b > ,
936
- pub current_module : Module < ' b > ,
937
- pub current_legacy_scope : LegacyScope < ' b > ,
938
- pub expansion : ExpnId ,
933
+ pub parent_scope : ParentScope < ' b > ,
939
934
}
940
935
941
936
impl < ' b > Deref for BuildReducedGraphVisitor < ' _ , ' b > {
@@ -955,11 +950,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
955
950
fn visit_invoc ( & mut self , id : ast:: NodeId ) -> & ' b InvocationData < ' b > {
956
951
let invoc_id = id. placeholder_to_expn_id ( ) ;
957
952
958
- self . current_module . unresolved_invocations . borrow_mut ( ) . insert ( invoc_id) ;
953
+ self . parent_scope . module . unresolved_invocations . borrow_mut ( ) . insert ( invoc_id) ;
959
954
960
955
let invocation_data = self . arenas . alloc_invocation_data ( InvocationData {
961
- module : self . current_module ,
962
- parent_legacy_scope : self . current_legacy_scope ,
956
+ module : self . parent_scope . module ,
957
+ parent_legacy_scope : self . parent_scope . legacy ,
963
958
output_legacy_scope : Cell :: new ( None ) ,
964
959
} ) ;
965
960
let old_invocation_data = self . invocations . insert ( invoc_id, invocation_data) ;
@@ -988,38 +983,32 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
988
983
method ! ( visit_ty: ast:: Ty , ast:: TyKind :: Mac , walk_ty) ;
989
984
990
985
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
- } ;
997
986
let macro_use = match item. node {
998
987
ItemKind :: MacroDef ( ..) => {
999
- self . current_legacy_scope = self . resolver . define_macro ( item, parent_scope) ;
988
+ self . parent_scope . legacy = self . resolver . define_macro ( item, & self . parent_scope ) ;
1000
989
return
1001
990
}
1002
991
ItemKind :: Mac ( ..) => {
1003
- self . current_legacy_scope = LegacyScope :: Invocation ( self . visit_invoc ( item. id ) ) ;
992
+ self . parent_scope . legacy = LegacyScope :: Invocation ( self . visit_invoc ( item. id ) ) ;
1004
993
return
1005
994
}
1006
995
ItemKind :: Mod ( ..) => self . contains_macro_use ( & item. attrs ) ,
1007
996
_ => false ,
1008
997
} ;
1009
998
1010
- let orig_current_module = self . current_module ;
1011
- let orig_current_legacy_scope = self . current_legacy_scope ;
1012
- self . build_reduced_graph_for_item ( item, parent_scope ) ;
999
+ let orig_current_module = self . parent_scope . module ;
1000
+ let orig_current_legacy_scope = self . parent_scope . legacy ;
1001
+ self . build_reduced_graph_for_item ( item) ;
1013
1002
visit:: walk_item ( self , item) ;
1014
- self . current_module = orig_current_module;
1003
+ self . parent_scope . module = orig_current_module;
1015
1004
if !macro_use {
1016
- self . current_legacy_scope = orig_current_legacy_scope;
1005
+ self . parent_scope . legacy = orig_current_legacy_scope;
1017
1006
}
1018
1007
}
1019
1008
1020
1009
fn visit_stmt ( & mut self , stmt : & ' a ast:: Stmt ) {
1021
1010
if let ast:: StmtKind :: Mac ( ..) = stmt. node {
1022
- self . current_legacy_scope = LegacyScope :: Invocation ( self . visit_invoc ( stmt. id ) ) ;
1011
+ self . parent_scope . legacy = LegacyScope :: Invocation ( self . visit_invoc ( stmt. id ) ) ;
1023
1012
} else {
1024
1013
visit:: walk_stmt ( self , stmt) ;
1025
1014
}
@@ -1031,21 +1020,21 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
1031
1020
return ;
1032
1021
}
1033
1022
1034
- self . build_reduced_graph_for_foreign_item ( foreign_item, self . expansion ) ;
1023
+ self . build_reduced_graph_for_foreign_item ( foreign_item) ;
1035
1024
visit:: walk_foreign_item ( self , foreign_item) ;
1036
1025
}
1037
1026
1038
1027
fn visit_block ( & mut self , block : & ' a Block ) {
1039
- let orig_current_module = self . current_module ;
1040
- let orig_current_legacy_scope = self . current_legacy_scope ;
1041
- self . build_reduced_graph_for_block ( block, self . expansion ) ;
1028
+ let orig_current_module = self . parent_scope . module ;
1029
+ let orig_current_legacy_scope = self . parent_scope . legacy ;
1030
+ self . build_reduced_graph_for_block ( block) ;
1042
1031
visit:: walk_block ( self , block) ;
1043
- self . current_module = orig_current_module;
1044
- self . current_legacy_scope = orig_current_legacy_scope;
1032
+ self . parent_scope . module = orig_current_module;
1033
+ self . parent_scope . legacy = orig_current_legacy_scope;
1045
1034
}
1046
1035
1047
1036
fn visit_trait_item ( & mut self , item : & ' a TraitItem ) {
1048
- let parent = self . current_module ;
1037
+ let parent = self . parent_scope . module ;
1049
1038
1050
1039
if let TraitItemKind :: Macro ( _) = item. node {
1051
1040
self . visit_invoc ( item. id ) ;
@@ -1067,11 +1056,12 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
1067
1056
} ;
1068
1057
1069
1058
let vis = ty:: Visibility :: Public ;
1070
- self . resolver . define ( parent, item. ident , ns, ( res, vis, item. span , self . expansion ) ) ;
1059
+ let expansion = self . parent_scope . expansion ;
1060
+ self . resolver . define ( parent, item. ident , ns, ( res, vis, item. span , expansion) ) ;
1071
1061
1072
- self . current_module = parent. parent . unwrap ( ) ; // nearest normal ancestor
1062
+ self . parent_scope . module = parent. parent . unwrap ( ) ; // nearest normal ancestor
1073
1063
visit:: walk_trait_item ( self , item) ;
1074
- self . current_module = parent;
1064
+ self . parent_scope . module = parent;
1075
1065
}
1076
1066
1077
1067
fn visit_token ( & mut self , t : Token ) {
@@ -1086,15 +1076,8 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
1086
1076
1087
1077
fn visit_attribute ( & mut self , attr : & ' a ast:: Attribute ) {
1088
1078
if !attr. is_sugared_doc && is_builtin_attr ( attr) {
1089
- let parent_scope = ParentScope {
1090
- module : self . current_module . nearest_item_scope ( ) ,
1091
- expansion : self . expansion ,
1092
- legacy : self . current_legacy_scope ,
1093
- // Let's hope discerning built-in attributes from derive helpers is not necessary
1094
- derives : Vec :: new ( ) ,
1095
- } ;
1096
- parent_scope. module . builtin_attrs . borrow_mut ( ) . push ( (
1097
- attr. path . segments [ 0 ] . ident , parent_scope
1079
+ self . parent_scope . module . builtin_attrs . borrow_mut ( ) . push ( (
1080
+ attr. path . segments [ 0 ] . ident , self . parent_scope . clone ( )
1098
1081
) ) ;
1099
1082
}
1100
1083
visit:: walk_attribute ( self , attr) ;
0 commit comments