@@ -157,19 +157,6 @@ impl<'a> Resolver<'a> {
157
157
self . macro_map . insert ( def_id, ext. clone ( ) ) ;
158
158
Some ( ext)
159
159
}
160
-
161
- /// Ensures that the reduced graph rooted at the given external module
162
- /// is built, building it if it is not.
163
- pub fn populate_module_if_necessary ( & mut self , module : Module < ' a > ) {
164
- if module. populated . get ( ) { return }
165
- let def_id = module. def_id ( ) . unwrap ( ) ;
166
- for child in self . cstore . item_children_untracked ( def_id, self . session ) {
167
- let child = child. map_id ( |_| panic ! ( "unexpected id" ) ) ;
168
- BuildReducedGraphVisitor { parent_scope : self . dummy_parent_scope ( ) , r : self }
169
- . build_reduced_graph_for_external_crate_res ( module, child) ;
170
- }
171
- module. populated . set ( true )
172
- }
173
160
}
174
161
175
162
pub struct BuildReducedGraphVisitor < ' a , ' b > {
@@ -595,7 +582,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
595
582
self . r . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
596
583
} ;
597
584
598
- self . r . populate_module_if_necessary ( module) ;
599
585
if let Some ( name) = self . r . session . parse_sess . injected_crate_name . try_get ( ) {
600
586
if name. as_str ( ) == ident. name . as_str ( ) {
601
587
self . r . injected_crate = Some ( module) ;
@@ -868,7 +854,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
868
854
}
869
855
870
856
/// Builds the reduced graph for a single item in an external crate.
871
- fn build_reduced_graph_for_external_crate_res (
857
+ crate fn build_reduced_graph_for_external_crate_res (
872
858
& mut self ,
873
859
parent : Module < ' a > ,
874
860
child : Export < ast:: NodeId > ,
@@ -879,88 +865,62 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
879
865
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.
880
866
let ident = ident. gensym_if_underscore ( ) ;
881
867
let expansion = ExpnId :: root ( ) ; // FIXME(jseyfried) intercrate hygiene
868
+ // Record primary definitions.
882
869
match res {
883
870
Res :: Def ( kind @ DefKind :: Mod , def_id)
884
- | Res :: Def ( kind @ DefKind :: Enum , def_id) => {
871
+ | Res :: Def ( kind @ DefKind :: Enum , def_id)
872
+ | Res :: Def ( kind @ DefKind :: Trait , def_id) => {
885
873
let module = self . r . new_module ( parent,
886
874
ModuleKind :: Def ( kind, def_id, ident. name ) ,
887
875
def_id,
888
876
expansion,
889
877
span) ;
890
- self . r . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
878
+ self . r . define ( parent, ident, TypeNS , ( module, vis, span , expansion) ) ;
891
879
}
892
- Res :: Def ( DefKind :: Variant , _)
880
+ Res :: Def ( DefKind :: Struct , _)
881
+ | Res :: Def ( DefKind :: Union , _)
882
+ | Res :: Def ( DefKind :: Variant , _)
893
883
| Res :: Def ( DefKind :: TyAlias , _)
894
884
| Res :: Def ( DefKind :: ForeignTy , _)
895
885
| Res :: Def ( DefKind :: OpaqueTy , _)
896
886
| Res :: Def ( DefKind :: TraitAlias , _)
887
+ | Res :: Def ( DefKind :: AssocTy , _)
888
+ | Res :: Def ( DefKind :: AssocOpaqueTy , _)
897
889
| Res :: PrimTy ( ..)
898
- | Res :: ToolMod => {
899
- self . r . define ( parent, ident, TypeNS , ( res, vis, DUMMY_SP , expansion) ) ;
900
- }
890
+ | Res :: ToolMod =>
891
+ self . r . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
901
892
Res :: Def ( DefKind :: Fn , _)
893
+ | Res :: Def ( DefKind :: Method , _)
902
894
| Res :: Def ( DefKind :: Static , _)
903
895
| Res :: Def ( DefKind :: Const , _)
904
- | Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ..) , _) => {
905
- self . r . define ( parent, ident, ValueNS , ( res, vis, DUMMY_SP , expansion) ) ;
906
- }
907
- Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ..) , def_id) => {
908
- self . r . define ( parent, ident, ValueNS , ( res, vis, DUMMY_SP , expansion) ) ;
909
-
910
- if let Some ( struct_def_id) =
911
- self . r . cstore . def_key ( def_id) . parent
912
- . map ( |index| DefId { krate : def_id. krate , index : index } ) {
913
- self . r . struct_constructors . insert ( struct_def_id, ( res, vis) ) ;
914
- }
915
- }
916
- Res :: Def ( DefKind :: Trait , def_id) => {
917
- let module_kind = ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ;
918
- let module = self . r . new_module ( parent,
919
- module_kind,
920
- parent. normal_ancestor_id ,
921
- expansion,
922
- span) ;
923
- self . r . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
924
-
925
- for child in self . r . cstore . item_children_untracked ( def_id, self . r . session ) {
926
- let res = child. res . map_id ( |_| panic ! ( "unexpected id" ) ) ;
927
- let ns = if let Res :: Def ( DefKind :: AssocTy , _) = res {
928
- TypeNS
929
- } else { ValueNS } ;
930
- self . r . define ( module, child. ident , ns,
931
- ( res, ty:: Visibility :: Public , DUMMY_SP , expansion) ) ;
932
-
933
- if self . r . cstore . associated_item_cloned_untracked ( child. res . def_id ( ) )
934
- . method_has_self_argument {
935
- self . r . has_self . insert ( res. def_id ( ) ) ;
936
- }
937
- }
938
- module. populated . set ( true ) ;
939
- }
896
+ | Res :: Def ( DefKind :: AssocConst , _)
897
+ | Res :: Def ( DefKind :: Ctor ( ..) , _) =>
898
+ self . r . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
899
+ Res :: Def ( DefKind :: Macro ( ..) , _)
900
+ | Res :: NonMacroAttr ( ..) =>
901
+ self . r . define ( parent, ident, MacroNS , ( res, vis, span, expansion) ) ,
902
+ Res :: Def ( DefKind :: TyParam , _) | Res :: Def ( DefKind :: ConstParam , _)
903
+ | Res :: Local ( ..) | Res :: SelfTy ( ..) | Res :: SelfCtor ( ..) | Res :: Err =>
904
+ bug ! ( "unexpected resolution: {:?}" , res)
905
+ }
906
+ // Record some extra data for better diagnostics.
907
+ match res {
940
908
Res :: Def ( DefKind :: Struct , def_id) | Res :: Def ( DefKind :: Union , def_id) => {
941
- self . r . define ( parent, ident, TypeNS , ( res, vis, DUMMY_SP , expansion) ) ;
942
-
943
- // Record field names for error reporting.
944
909
let field_names = self . r . cstore . struct_field_names_untracked ( def_id) ;
945
910
self . insert_field_names ( def_id, field_names) ;
946
911
}
947
- Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
948
- self . r . define ( parent, ident, MacroNS , ( res, vis, DUMMY_SP , expansion) ) ;
912
+ Res :: Def ( DefKind :: Method , def_id) => {
913
+ if self . r . cstore . associated_item_cloned_untracked ( def_id) . method_has_self_argument {
914
+ self . r . has_self . insert ( def_id) ;
915
+ }
916
+ }
917
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ..) , def_id) => {
918
+ let parent = self . r . cstore . def_key ( def_id) . parent ;
919
+ if let Some ( struct_def_id) = parent. map ( |index| DefId { index, ..def_id } ) {
920
+ self . r . struct_constructors . insert ( struct_def_id, ( res, vis) ) ;
921
+ }
949
922
}
950
- _ => bug ! ( "unexpected resolution: {:?}" , res)
951
- }
952
- }
953
-
954
- fn legacy_import_macro ( & mut self ,
955
- name : Name ,
956
- binding : & ' a NameBinding < ' a > ,
957
- span : Span ,
958
- allow_shadowing : bool ) {
959
- if self . r . macro_use_prelude . insert ( name, binding) . is_some ( ) && !allow_shadowing {
960
- let msg = format ! ( "`{}` is already in scope" , name) ;
961
- let note =
962
- "macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)" ;
963
- self . r . session . struct_span_err ( span, & msg) . note ( note) . emit ( ) ;
923
+ _ => { }
964
924
}
965
925
}
966
926
@@ -1021,9 +981,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1021
981
if let Some ( span) = import_all {
1022
982
let directive = macro_use_directive ( self , span) ;
1023
983
self . r . potentially_unused_imports . push ( directive) ;
1024
- module . for_each_child ( | ident, ns, binding| if ns == MacroNS {
1025
- let imported_binding = self . r . import ( binding, directive) ;
1026
- self . legacy_import_macro ( ident. name , imported_binding, span, allow_shadowing) ;
984
+ self . r . for_each_child ( module , |this , ident, ns, binding| if ns == MacroNS {
985
+ let imported_binding = this . import ( binding, directive) ;
986
+ this . legacy_import_macro ( ident. name , imported_binding, span, allow_shadowing) ;
1027
987
} ) ;
1028
988
} else {
1029
989
for ident in single_imports. iter ( ) . cloned ( ) {
@@ -1039,8 +999,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1039
999
let directive = macro_use_directive ( self , ident. span ) ;
1040
1000
self . r . potentially_unused_imports . push ( directive) ;
1041
1001
let imported_binding = self . r . import ( binding, directive) ;
1042
- self . legacy_import_macro ( ident. name , imported_binding,
1043
- ident. span , allow_shadowing) ;
1002
+ self . r . legacy_import_macro ( ident. name , imported_binding,
1003
+ ident. span , allow_shadowing) ;
1044
1004
} else {
1045
1005
span_err ! ( self . r. session, ident. span, E0469 , "imported macro not found" ) ;
1046
1006
}
0 commit comments