@@ -1195,13 +1195,6 @@ impl<'a> ModuleData<'a> {
11951195 }
11961196 }
11971197
1198- fn is_trait_alias ( & self ) -> bool {
1199- match self . kind {
1200- ModuleKind :: Def ( Def :: TraitAlias ( _) , _) => true ,
1201- _ => false ,
1202- }
1203- }
1204-
12051198 fn nearest_item_scope ( & ' a self ) -> Module < ' a > {
12061199 if self . is_trait ( ) { self . parent . unwrap ( ) } else { self }
12071200 }
@@ -1359,7 +1352,7 @@ impl<'a> NameBinding<'a> {
13591352 }
13601353 }
13611354
1362- // We sometimes need to treat variants as `pub` for backwards compatibility
1355+ // We sometimes need to treat variants as `pub` for backwards compatibility.
13631356 fn pseudo_vis ( & self ) -> ty:: Visibility {
13641357 if self . is_variant ( ) && self . def ( ) . def_id ( ) . is_local ( ) {
13651358 ty:: Visibility :: Public
@@ -2717,7 +2710,7 @@ impl<'a> Resolver<'a> {
27172710 {
27182711 let mut self_type_rib = Rib :: new ( NormalRibKind ) ;
27192712
2720- // plain insert (no renaming, types are not currently hygienic.... )
2713+ // Plain insert (no renaming, since types are not currently hygienic)
27212714 self_type_rib. bindings . insert ( keywords:: SelfUpper . ident ( ) , self_def) ;
27222715 self . ribs [ TypeNS ] . push ( self_type_rib) ;
27232716 f ( self ) ;
@@ -4386,18 +4379,37 @@ impl<'a> Resolver<'a> {
43864379 }
43874380
43884381 for & ( trait_name, binding) in traits. as_ref ( ) . unwrap ( ) . iter ( ) {
4389- let module = binding. module ( ) . unwrap ( ) ;
4390- let mut ident = ident;
4391- if ident. span . glob_adjust ( module. expansion , binding. span . ctxt ( ) . modern ( ) ) . is_none ( ) {
4392- continue
4393- }
4394- if self . resolve_ident_in_module_unadjusted (
4395- ModuleOrUniformRoot :: Module ( module) ,
4396- ident,
4397- ns,
4398- false ,
4399- module. span ,
4400- ) . is_ok ( ) {
4382+ // Traits have pseudo-modules that can be used to search for the given ident.
4383+ if let Some ( module) = binding. module ( ) {
4384+ let mut ident = ident;
4385+ if ident. span . glob_adjust (
4386+ module. expansion ,
4387+ binding. span . ctxt ( ) . modern ( ) ,
4388+ ) . is_none ( ) {
4389+ continue
4390+ }
4391+ if self . resolve_ident_in_module_unadjusted (
4392+ ModuleOrUniformRoot :: Module ( module) ,
4393+ ident,
4394+ ns,
4395+ false ,
4396+ module. span ,
4397+ ) . is_ok ( ) {
4398+ let import_id = match binding. kind {
4399+ NameBindingKind :: Import { directive, .. } => {
4400+ self . maybe_unused_trait_imports . insert ( directive. id ) ;
4401+ self . add_to_glob_map ( & directive, trait_name) ;
4402+ Some ( directive. id )
4403+ }
4404+ _ => None ,
4405+ } ;
4406+ let trait_def_id = module. def_id ( ) . unwrap ( ) ;
4407+ found_traits. push ( TraitCandidate { def_id : trait_def_id, import_id } ) ;
4408+ }
4409+ } else if let Def :: TraitAlias ( _) = binding. def ( ) {
4410+ // For now, just treat all trait aliases as possible candidates, since we don't
4411+ // know if the ident is somewhere in the transitive bounds.
4412+
44014413 let import_id = match binding. kind {
44024414 NameBindingKind :: Import { directive, .. } => {
44034415 self . maybe_unused_trait_imports . insert ( directive. id ) ;
@@ -4406,8 +4418,10 @@ impl<'a> Resolver<'a> {
44064418 }
44074419 _ => None ,
44084420 } ;
4409- let trait_def_id = module. def_id ( ) . unwrap ( ) ;
4410- found_traits. push ( TraitCandidate { def_id : trait_def_id, import_id : import_id } ) ;
4421+ let trait_def_id = binding. def ( ) . def_id ( ) ;
4422+ found_traits. push ( TraitCandidate { def_id : trait_def_id, import_id } ) ;
4423+ } else {
4424+ bug ! ( "candidate is not trait or trait alias?" )
44114425 }
44124426 }
44134427 }
@@ -4843,7 +4857,6 @@ impl<'a> Resolver<'a> {
48434857 let container = match parent. kind {
48444858 ModuleKind :: Def ( Def :: Mod ( _) , _) => "module" ,
48454859 ModuleKind :: Def ( Def :: Trait ( _) , _) => "trait" ,
4846- ModuleKind :: Def ( Def :: TraitAlias ( _) , _) => "trait alias" ,
48474860 ModuleKind :: Block ( ..) => "block" ,
48484861 _ => "enum" ,
48494862 } ;
@@ -4872,7 +4885,6 @@ impl<'a> Resolver<'a> {
48724885 ( TypeNS , _) if old_binding. is_extern_crate ( ) => "extern crate" ,
48734886 ( TypeNS , Some ( module) ) if module. is_normal ( ) => "module" ,
48744887 ( TypeNS , Some ( module) ) if module. is_trait ( ) => "trait" ,
4875- ( TypeNS , Some ( module) ) if module. is_trait_alias ( ) => "trait alias" ,
48764888 ( TypeNS , _) => "type" ,
48774889 } ;
48784890
0 commit comments