@@ -365,7 +365,6 @@ impl<'a> Resolver<'a> {
365365 self . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
366366 } ;
367367
368- self . populate_module_if_necessary ( module) ;
369368 if let Some ( name) = self . session . parse_sess . injected_crate_name . try_get ( ) {
370369 if name. as_str ( ) == ident. name . as_str ( ) {
371370 self . injected_crate = Some ( module) ;
@@ -632,7 +631,7 @@ impl<'a> Resolver<'a> {
632631 }
633632
634633 /// Builds the reduced graph for a single item in an external crate.
635- fn build_reduced_graph_for_external_crate_res (
634+ crate fn build_reduced_graph_for_external_crate_res (
636635 & mut self ,
637636 parent : Module < ' a > ,
638637 child : Export < ast:: NodeId > ,
@@ -643,75 +642,62 @@ impl<'a> Resolver<'a> {
643642 // This is only a guess, two equivalent idents may incorrectly get different gensyms here.
644643 let ident = ident. gensym_if_underscore ( ) ;
645644 let expansion = ExpnId :: root ( ) ; // FIXME(jseyfried) intercrate hygiene
645+ // Record primary definitions.
646646 match res {
647647 Res :: Def ( kind @ DefKind :: Mod , def_id)
648- | Res :: Def ( kind @ DefKind :: Enum , def_id) => {
648+ | Res :: Def ( kind @ DefKind :: Enum , def_id)
649+ | Res :: Def ( kind @ DefKind :: Trait , def_id) => {
649650 let module = self . new_module ( parent,
650651 ModuleKind :: Def ( kind, def_id, ident. name ) ,
651652 def_id,
652653 expansion,
653654 span) ;
654- self . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
655+ self . define ( parent, ident, TypeNS , ( module, vis, span , expansion) ) ;
655656 }
656- Res :: Def ( DefKind :: Variant , _)
657+ Res :: Def ( DefKind :: Struct , _)
658+ | Res :: Def ( DefKind :: Union , _)
659+ | Res :: Def ( DefKind :: Variant , _)
657660 | Res :: Def ( DefKind :: TyAlias , _)
658661 | Res :: Def ( DefKind :: ForeignTy , _)
659662 | Res :: Def ( DefKind :: OpaqueTy , _)
660663 | Res :: Def ( DefKind :: TraitAlias , _)
664+ | Res :: Def ( DefKind :: AssocTy , _)
665+ | Res :: Def ( DefKind :: AssocOpaqueTy , _)
661666 | Res :: PrimTy ( ..)
662- | Res :: ToolMod => {
663- self . define ( parent, ident, TypeNS , ( res, vis, DUMMY_SP , expansion) ) ;
664- }
667+ | Res :: ToolMod =>
668+ self . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
665669 Res :: Def ( DefKind :: Fn , _)
670+ | Res :: Def ( DefKind :: Method , _)
666671 | Res :: Def ( DefKind :: Static , _)
667672 | Res :: Def ( DefKind :: Const , _)
668- | Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ..) , _) => {
669- self . define ( parent, ident, ValueNS , ( res, vis, DUMMY_SP , expansion) ) ;
670- }
671- Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ..) , def_id) => {
672- self . define ( parent, ident, ValueNS , ( res, vis, DUMMY_SP , expansion) ) ;
673-
674- if let Some ( struct_def_id) =
675- self . cstore . def_key ( def_id) . parent
676- . map ( |index| DefId { krate : def_id. krate , index : index } ) {
677- self . struct_constructors . insert ( struct_def_id, ( res, vis) ) ;
678- }
679- }
680- Res :: Def ( DefKind :: Trait , def_id) => {
681- let module_kind = ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ;
682- let module = self . new_module ( parent,
683- module_kind,
684- parent. normal_ancestor_id ,
685- expansion,
686- span) ;
687- self . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
688-
689- for child in self . cstore . item_children_untracked ( def_id, self . session ) {
690- let res = child. res . map_id ( |_| panic ! ( "unexpected id" ) ) ;
691- let ns = if let Res :: Def ( DefKind :: AssocTy , _) = res {
692- TypeNS
693- } else { ValueNS } ;
694- self . define ( module, child. ident , ns,
695- ( res, ty:: Visibility :: Public , DUMMY_SP , expansion) ) ;
696-
697- if self . cstore . associated_item_cloned_untracked ( child. res . def_id ( ) )
698- . method_has_self_argument {
699- self . has_self . insert ( res. def_id ( ) ) ;
700- }
701- }
702- module. populated . set ( true ) ;
703- }
673+ | Res :: Def ( DefKind :: AssocConst , _)
674+ | Res :: Def ( DefKind :: Ctor ( ..) , _) =>
675+ self . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
676+ Res :: Def ( DefKind :: Macro ( ..) , _)
677+ | Res :: NonMacroAttr ( ..) =>
678+ self . define ( parent, ident, MacroNS , ( res, vis, span, expansion) ) ,
679+ Res :: Def ( DefKind :: TyParam , _) | Res :: Def ( DefKind :: ConstParam , _)
680+ | Res :: Local ( ..) | Res :: SelfTy ( ..) | Res :: SelfCtor ( ..) | Res :: Err =>
681+ bug ! ( "unexpected resolution: {:?}" , res)
682+ }
683+ // Record some extra data for better diagnostics.
684+ match res {
704685 Res :: Def ( DefKind :: Struct , def_id) | Res :: Def ( DefKind :: Union , def_id) => {
705- self . define ( parent, ident, TypeNS , ( res, vis, DUMMY_SP , expansion) ) ;
706-
707- // Record field names for error reporting.
708686 let field_names = self . cstore . struct_field_names_untracked ( def_id) ;
709687 self . insert_field_names ( def_id, field_names) ;
710688 }
711- Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
712- self . define ( parent, ident, MacroNS , ( res, vis, DUMMY_SP , expansion) ) ;
689+ Res :: Def ( DefKind :: Method , def_id) => {
690+ if self . cstore . associated_item_cloned_untracked ( def_id) . method_has_self_argument {
691+ self . has_self . insert ( def_id) ;
692+ }
693+ }
694+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ..) , def_id) => {
695+ let parent = self . cstore . def_key ( def_id) . parent ;
696+ if let Some ( struct_def_id) = parent. map ( |index| DefId { index, ..def_id } ) {
697+ self . struct_constructors . insert ( struct_def_id, ( res, vis) ) ;
698+ }
713699 }
714- _ => bug ! ( "unexpected resolution: {:?}" , res )
700+ _ => { }
715701 }
716702 }
717703
@@ -780,18 +766,6 @@ impl<'a> Resolver<'a> {
780766 Some ( ext)
781767 }
782768
783- /// Ensures that the reduced graph rooted at the given external module
784- /// is built, building it if it is not.
785- pub fn populate_module_if_necessary ( & mut self , module : Module < ' a > ) {
786- if module. populated . get ( ) { return }
787- let def_id = module. def_id ( ) . unwrap ( ) ;
788- for child in self . cstore . item_children_untracked ( def_id, self . session ) {
789- let child = child. map_id ( |_| panic ! ( "unexpected id" ) ) ;
790- self . build_reduced_graph_for_external_crate_res ( module, child) ;
791- }
792- module. populated . set ( true )
793- }
794-
795769 fn legacy_import_macro ( & mut self ,
796770 name : Name ,
797771 binding : & ' a NameBinding < ' a > ,
@@ -863,9 +837,9 @@ impl<'a> Resolver<'a> {
863837 if let Some ( span) = import_all {
864838 let directive = macro_use_directive ( span) ;
865839 self . potentially_unused_imports . push ( directive) ;
866- module . for_each_child ( | ident, ns, binding| if ns == MacroNS {
867- let imported_binding = self . import ( binding, directive) ;
868- self . legacy_import_macro ( ident. name , imported_binding, span, allow_shadowing) ;
840+ self . for_each_child ( module , |this , ident, ns, binding| if ns == MacroNS {
841+ let imported_binding = this . import ( binding, directive) ;
842+ this . legacy_import_macro ( ident. name , imported_binding, span, allow_shadowing) ;
869843 } ) ;
870844 } else {
871845 for ident in single_imports. iter ( ) . cloned ( ) {
0 commit comments