@@ -365,7 +365,6 @@ impl<'a> Resolver<'a> {
365
365
self . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
366
366
} ;
367
367
368
- self . populate_module_if_necessary ( module) ;
369
368
if let Some ( name) = self . session . parse_sess . injected_crate_name . try_get ( ) {
370
369
if name. as_str ( ) == ident. name . as_str ( ) {
371
370
self . injected_crate = Some ( module) ;
@@ -632,7 +631,7 @@ impl<'a> Resolver<'a> {
632
631
}
633
632
634
633
/// 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 (
636
635
& mut self ,
637
636
parent : Module < ' a > ,
638
637
child : Export < ast:: NodeId > ,
@@ -643,75 +642,62 @@ impl<'a> Resolver<'a> {
643
642
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.
644
643
let ident = ident. gensym_if_underscore ( ) ;
645
644
let expansion = ExpnId :: root ( ) ; // FIXME(jseyfried) intercrate hygiene
645
+ // Record primary definitions.
646
646
match res {
647
647
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) => {
649
650
let module = self . new_module ( parent,
650
651
ModuleKind :: Def ( kind, def_id, ident. name ) ,
651
652
def_id,
652
653
expansion,
653
654
span) ;
654
- self . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , expansion) ) ;
655
+ self . define ( parent, ident, TypeNS , ( module, vis, span , expansion) ) ;
655
656
}
656
- Res :: Def ( DefKind :: Variant , _)
657
+ Res :: Def ( DefKind :: Struct , _)
658
+ | Res :: Def ( DefKind :: Union , _)
659
+ | Res :: Def ( DefKind :: Variant , _)
657
660
| Res :: Def ( DefKind :: TyAlias , _)
658
661
| Res :: Def ( DefKind :: ForeignTy , _)
659
662
| Res :: Def ( DefKind :: OpaqueTy , _)
660
663
| Res :: Def ( DefKind :: TraitAlias , _)
664
+ | Res :: Def ( DefKind :: AssocTy , _)
665
+ | Res :: Def ( DefKind :: AssocOpaqueTy , _)
661
666
| 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) ) ,
665
669
Res :: Def ( DefKind :: Fn , _)
670
+ | Res :: Def ( DefKind :: Method , _)
666
671
| Res :: Def ( DefKind :: Static , _)
667
672
| 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 {
704
685
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.
708
686
let field_names = self . cstore . struct_field_names_untracked ( def_id) ;
709
687
self . insert_field_names ( def_id, field_names) ;
710
688
}
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
+ }
713
699
}
714
- _ => bug ! ( "unexpected resolution: {:?}" , res )
700
+ _ => { }
715
701
}
716
702
}
717
703
@@ -780,18 +766,6 @@ impl<'a> Resolver<'a> {
780
766
Some ( ext)
781
767
}
782
768
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
-
795
769
fn legacy_import_macro ( & mut self ,
796
770
name : Name ,
797
771
binding : & ' a NameBinding < ' a > ,
@@ -863,9 +837,9 @@ impl<'a> Resolver<'a> {
863
837
if let Some ( span) = import_all {
864
838
let directive = macro_use_directive ( span) ;
865
839
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) ;
869
843
} ) ;
870
844
} else {
871
845
for ident in single_imports. iter ( ) . cloned ( ) {
0 commit comments