@@ -417,58 +417,38 @@ impl<'a> Resolver<'a> {
417417 let ident = Ident :: with_empty_ctxt ( child. name ) ;
418418 let def = child. def ;
419419 let def_id = def. def_id ( ) ;
420- let vis = match def {
421- Def :: Macro ( ..) => ty:: Visibility :: Public ,
422- _ if parent. is_trait ( ) => ty:: Visibility :: Public ,
423- _ => self . session . cstore . visibility ( def_id) ,
424- } ;
420+ let vis = self . session . cstore . visibility ( def_id) ;
425421
426422 match def {
427423 Def :: Mod ( ..) | Def :: Enum ( ..) => {
428424 let module = self . new_module ( parent, ModuleKind :: Def ( def, ident. name ) , def_id) ;
429425 self . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
430426 }
431- Def :: Variant ( ..) => {
427+ Def :: Variant ( ..) | Def :: TyAlias ( .. ) => {
432428 self . define ( parent, ident, TypeNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
433429 }
434- Def :: VariantCtor ( ..) => {
435- self . define ( parent, ident, ValueNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
436- }
437- Def :: Fn ( ..) |
438- Def :: Static ( ..) |
439- Def :: Const ( ..) |
440- Def :: AssociatedConst ( ..) |
441- Def :: Method ( ..) => {
430+ Def :: Fn ( ..) | Def :: Static ( ..) | Def :: Const ( ..) |
431+ Def :: VariantCtor ( ..) | Def :: StructCtor ( ..) => {
442432 self . define ( parent, ident, ValueNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
443433 }
444434 Def :: Trait ( ..) => {
445435 let module_kind = ModuleKind :: Def ( def, ident. name ) ;
446436 let module = self . new_module ( parent, module_kind, parent. normal_ancestor_id ) ;
447437 self . define ( parent, ident, TypeNS , ( module, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
448438
449- // If this is a trait, add all the trait item names to the trait info.
450- let trait_item_def_ids = self . session . cstore . associated_item_def_ids ( def_id) ;
451- for trait_item_def_id in trait_item_def_ids {
452- let trait_item_name = self . session . cstore . def_key ( trait_item_def_id)
453- . disambiguated_data . data . get_opt_name ( )
454- . expect ( "opt_item_name returned None for trait" ) ;
455- self . trait_item_map . insert ( ( trait_item_name, def_id) , false ) ;
456- }
457- }
458- Def :: TyAlias ( ..) | Def :: AssociatedTy ( ..) => {
459- self . define ( parent, ident, TypeNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
460- }
461- Def :: Struct ( ..) => {
462- self . define ( parent, ident, TypeNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
439+ for child in self . session . cstore . item_children ( def_id) {
440+ let ns = if let Def :: AssociatedTy ( ..) = child. def { TypeNS } else { ValueNS } ;
441+ let ident = Ident :: with_empty_ctxt ( child. name ) ;
442+ self . define ( module, ident, ns, ( child. def , ty:: Visibility :: Public ,
443+ DUMMY_SP , Mark :: root ( ) ) ) ;
463444
464- // Record field names for error reporting.
465- let field_names = self . session . cstore . struct_field_names ( def_id) ;
466- self . insert_field_names ( def_id, field_names) ;
467- }
468- Def :: StructCtor ( ..) => {
469- self . define ( parent, ident, ValueNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
445+ let has_self = self . session . cstore . associated_item ( child. def . def_id ( ) )
446+ . map_or ( false , |item| item. method_has_self_argument ) ;
447+ self . trait_item_map . insert ( ( def_id, child. name , ns) , ( child. def , has_self) ) ;
448+ }
449+ module. populated . set ( true ) ;
470450 }
471- Def :: Union ( ..) => {
451+ Def :: Struct ( .. ) | Def :: Union ( ..) => {
472452 self . define ( parent, ident, TypeNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
473453
474454 // Record field names for error reporting.
@@ -478,15 +458,7 @@ impl<'a> Resolver<'a> {
478458 Def :: Macro ( ..) => {
479459 self . define ( parent, ident, MacroNS , ( def, vis, DUMMY_SP , Mark :: root ( ) ) ) ;
480460 }
481- Def :: Local ( ..) |
482- Def :: PrimTy ( ..) |
483- Def :: TyParam ( ..) |
484- Def :: Upvar ( ..) |
485- Def :: Label ( ..) |
486- Def :: SelfTy ( ..) |
487- Def :: Err => {
488- bug ! ( "unexpected definition: {:?}" , def) ;
489- }
461+ _ => bug ! ( "unexpected definition: {:?}" , def)
490462 }
491463 }
492464
@@ -751,18 +723,15 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> {
751723
752724 // Add the item to the trait info.
753725 let item_def_id = self . resolver . definitions . local_def_id ( item. id ) ;
754- let mut is_static_method = false ;
755- let ( def, ns) = match item. node {
756- TraitItemKind :: Const ( ..) => ( Def :: AssociatedConst ( item_def_id) , ValueNS ) ,
757- TraitItemKind :: Method ( ref sig, _) => {
758- is_static_method = !sig. decl . has_self ( ) ;
759- ( Def :: Method ( item_def_id) , ValueNS )
760- }
761- TraitItemKind :: Type ( ..) => ( Def :: AssociatedTy ( item_def_id) , TypeNS ) ,
726+ let ( def, ns, has_self) = match item. node {
727+ TraitItemKind :: Const ( ..) => ( Def :: AssociatedConst ( item_def_id) , ValueNS , false ) ,
728+ TraitItemKind :: Method ( ref sig, _) =>
729+ ( Def :: Method ( item_def_id) , ValueNS , sig. decl . has_self ( ) ) ,
730+ TraitItemKind :: Type ( ..) => ( Def :: AssociatedTy ( item_def_id) , TypeNS , false ) ,
762731 TraitItemKind :: Macro ( _) => bug ! ( ) , // handled above
763732 } ;
764733
765- self . resolver . trait_item_map . insert ( ( item. ident . name , def_id ) , is_static_method ) ;
734+ self . resolver . trait_item_map . insert ( ( def_id , item. ident . name , ns ) , ( def , has_self ) ) ;
766735
767736 let vis = ty:: Visibility :: Public ;
768737 self . resolver . define ( parent, item. ident , ns, ( def, vis, item. span , self . expansion ) ) ;
0 commit comments