@@ -157,19 +157,6 @@ impl<'a> Resolver<'a> {
157157 self . macro_map . insert ( def_id, ext. clone ( ) ) ;
158158 Some ( ext)
159159 }
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- }
173160}
174161
175162pub struct BuildReducedGraphVisitor < ' a , ' b > {
@@ -595,7 +582,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
595582 self . r . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
596583 } ;
597584
598- self . r . populate_module_if_necessary ( module) ;
599585 if let Some ( name) = self . r . session . parse_sess . injected_crate_name . try_get ( ) {
600586 if name. as_str ( ) == ident. name . as_str ( ) {
601587 self . r . injected_crate = Some ( module) ;
@@ -868,7 +854,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
868854 }
869855
870856 /// 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 (
872858 & mut self ,
873859 parent : Module < ' a > ,
874860 child : Export < ast:: NodeId > ,
@@ -879,88 +865,62 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
879865 // This is only a guess, two equivalent idents may incorrectly get different gensyms here.
880866 let ident = ident. gensym_if_underscore ( ) ;
881867 let expansion = ExpnId :: root ( ) ; // FIXME(jseyfried) intercrate hygiene
868+ // Record primary definitions.
882869 match res {
883870 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) => {
885873 let module = self . r . new_module ( parent,
886874 ModuleKind :: Def ( kind, def_id, ident. name ) ,
887875 def_id,
888876 expansion,
889877 span) ;
890- self . r . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
878+ self . r . define ( parent, ident, TypeNS , ( module, vis, span , expansion) ) ;
891879 }
892- Res :: Def ( DefKind :: Variant , _)
880+ Res :: Def ( DefKind :: Struct , _)
881+ | Res :: Def ( DefKind :: Union , _)
882+ | Res :: Def ( DefKind :: Variant , _)
893883 | Res :: Def ( DefKind :: TyAlias , _)
894884 | Res :: Def ( DefKind :: ForeignTy , _)
895885 | Res :: Def ( DefKind :: OpaqueTy , _)
896886 | Res :: Def ( DefKind :: TraitAlias , _)
887+ | Res :: Def ( DefKind :: AssocTy , _)
888+ | Res :: Def ( DefKind :: AssocOpaqueTy , _)
897889 | 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) ) ,
901892 Res :: Def ( DefKind :: Fn , _)
893+ | Res :: Def ( DefKind :: Method , _)
902894 | Res :: Def ( DefKind :: Static , _)
903895 | 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 {
940908 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.
944909 let field_names = self . r . cstore . struct_field_names_untracked ( def_id) ;
945910 self . insert_field_names ( def_id, field_names) ;
946911 }
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+ }
949922 }
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+ _ => { }
964924 }
965925 }
966926
@@ -1021,9 +981,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1021981 if let Some ( span) = import_all {
1022982 let directive = macro_use_directive ( self , span) ;
1023983 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) ;
1027987 } ) ;
1028988 } else {
1029989 for ident in single_imports. iter ( ) . cloned ( ) {
@@ -1039,8 +999,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1039999 let directive = macro_use_directive ( self , ident. span ) ;
10401000 self . r . potentially_unused_imports . push ( directive) ;
10411001 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) ;
10441004 } else {
10451005 span_err ! ( self . r. session, ident. span, E0469 , "imported macro not found" ) ;
10461006 }
0 commit comments