@@ -1195,13 +1195,6 @@ impl<'a> ModuleData<'a> {
1195
1195
}
1196
1196
}
1197
1197
1198
- fn is_trait_alias ( & self ) -> bool {
1199
- match self . kind {
1200
- ModuleKind :: Def ( Def :: TraitAlias ( _) , _) => true ,
1201
- _ => false ,
1202
- }
1203
- }
1204
-
1205
1198
fn nearest_item_scope ( & ' a self ) -> Module < ' a > {
1206
1199
if self . is_trait ( ) { self . parent . unwrap ( ) } else { self }
1207
1200
}
@@ -1359,7 +1352,7 @@ impl<'a> NameBinding<'a> {
1359
1352
}
1360
1353
}
1361
1354
1362
- // We sometimes need to treat variants as `pub` for backwards compatibility
1355
+ // We sometimes need to treat variants as `pub` for backwards compatibility.
1363
1356
fn pseudo_vis ( & self ) -> ty:: Visibility {
1364
1357
if self . is_variant ( ) && self . def ( ) . def_id ( ) . is_local ( ) {
1365
1358
ty:: Visibility :: Public
@@ -2717,7 +2710,7 @@ impl<'a> Resolver<'a> {
2717
2710
{
2718
2711
let mut self_type_rib = Rib :: new ( NormalRibKind ) ;
2719
2712
2720
- // plain insert (no renaming, types are not currently hygienic.... )
2713
+ // Plain insert (no renaming, since types are not currently hygienic)
2721
2714
self_type_rib. bindings . insert ( keywords:: SelfUpper . ident ( ) , self_def) ;
2722
2715
self . ribs [ TypeNS ] . push ( self_type_rib) ;
2723
2716
f ( self ) ;
@@ -4386,18 +4379,37 @@ impl<'a> Resolver<'a> {
4386
4379
}
4387
4380
4388
4381
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
+
4401
4413
let import_id = match binding. kind {
4402
4414
NameBindingKind :: Import { directive, .. } => {
4403
4415
self . maybe_unused_trait_imports . insert ( directive. id ) ;
@@ -4406,8 +4418,10 @@ impl<'a> Resolver<'a> {
4406
4418
}
4407
4419
_ => None ,
4408
4420
} ;
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?" )
4411
4425
}
4412
4426
}
4413
4427
}
@@ -4843,7 +4857,6 @@ impl<'a> Resolver<'a> {
4843
4857
let container = match parent. kind {
4844
4858
ModuleKind :: Def ( Def :: Mod ( _) , _) => "module" ,
4845
4859
ModuleKind :: Def ( Def :: Trait ( _) , _) => "trait" ,
4846
- ModuleKind :: Def ( Def :: TraitAlias ( _) , _) => "trait alias" ,
4847
4860
ModuleKind :: Block ( ..) => "block" ,
4848
4861
_ => "enum" ,
4849
4862
} ;
@@ -4872,7 +4885,6 @@ impl<'a> Resolver<'a> {
4872
4885
( TypeNS , _) if old_binding. is_extern_crate ( ) => "extern crate" ,
4873
4886
( TypeNS , Some ( module) ) if module. is_normal ( ) => "module" ,
4874
4887
( TypeNS , Some ( module) ) if module. is_trait ( ) => "trait" ,
4875
- ( TypeNS , Some ( module) ) if module. is_trait_alias ( ) => "trait alias" ,
4876
4888
( TypeNS , _) => "type" ,
4877
4889
} ;
4878
4890
0 commit comments