@@ -390,12 +390,18 @@ impl PatternSource {
390
390
}
391
391
}
392
392
393
+ #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
394
+ enum AliasPossibility {
395
+ No ,
396
+ Maybe ,
397
+ }
398
+
393
399
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
394
400
enum PathSource < ' a > {
395
401
// Type paths `Path`.
396
402
Type ,
397
403
// Trait paths in bounds or impls.
398
- Trait ,
404
+ Trait ( AliasPossibility ) ,
399
405
// Expression paths `path`, with optional parent context.
400
406
Expr ( Option < & ' a Expr > ) ,
401
407
// Paths in path patterns `Path`.
@@ -415,7 +421,7 @@ enum PathSource<'a> {
415
421
impl < ' a > PathSource < ' a > {
416
422
fn namespace ( self ) -> Namespace {
417
423
match self {
418
- PathSource :: Type | PathSource :: Trait | PathSource :: Struct |
424
+ PathSource :: Type | PathSource :: Trait ( _ ) | PathSource :: Struct |
419
425
PathSource :: Visibility | PathSource :: ImportPrefix => TypeNS ,
420
426
PathSource :: Expr ( ..) | PathSource :: Pat | PathSource :: TupleStruct => ValueNS ,
421
427
PathSource :: TraitItem ( ns) => ns,
@@ -427,23 +433,23 @@ impl<'a> PathSource<'a> {
427
433
PathSource :: Visibility | PathSource :: ImportPrefix => true ,
428
434
PathSource :: Type | PathSource :: Expr ( ..) | PathSource :: Pat |
429
435
PathSource :: Struct | PathSource :: TupleStruct |
430
- PathSource :: Trait | PathSource :: TraitItem ( ..) => false ,
436
+ PathSource :: Trait ( _ ) | PathSource :: TraitItem ( ..) => false ,
431
437
}
432
438
}
433
439
434
440
fn defer_to_typeck ( self ) -> bool {
435
441
match self {
436
442
PathSource :: Type | PathSource :: Expr ( ..) | PathSource :: Pat |
437
443
PathSource :: Struct | PathSource :: TupleStruct => true ,
438
- PathSource :: Trait | PathSource :: TraitItem ( ..) |
444
+ PathSource :: Trait ( _ ) | PathSource :: TraitItem ( ..) |
439
445
PathSource :: Visibility | PathSource :: ImportPrefix => false ,
440
446
}
441
447
}
442
448
443
449
fn descr_expected ( self ) -> & ' static str {
444
450
match self {
445
451
PathSource :: Type => "type" ,
446
- PathSource :: Trait => "trait" ,
452
+ PathSource :: Trait ( _ ) => "trait" ,
447
453
PathSource :: Pat => "unit struct/variant or constant" ,
448
454
PathSource :: Struct => "struct, variant or union type" ,
449
455
PathSource :: TupleStruct => "tuple struct/variant" ,
@@ -472,10 +478,15 @@ impl<'a> PathSource<'a> {
472
478
Def :: TyForeign ( ..) => true ,
473
479
_ => false ,
474
480
} ,
475
- PathSource :: Trait => match def {
481
+ PathSource :: Trait ( AliasPossibility :: No ) => match def {
476
482
Def :: Trait ( ..) => true ,
477
483
_ => false ,
478
484
} ,
485
+ PathSource :: Trait ( AliasPossibility :: Maybe ) => match def {
486
+ Def :: Trait ( ..) => true ,
487
+ Def :: TraitAlias ( ..) => true ,
488
+ _ => false ,
489
+ } ,
479
490
PathSource :: Expr ( ..) => match def {
480
491
Def :: StructCtor ( _, CtorKind :: Const ) | Def :: StructCtor ( _, CtorKind :: Fn ) |
481
492
Def :: VariantCtor ( _, CtorKind :: Const ) | Def :: VariantCtor ( _, CtorKind :: Fn ) |
@@ -530,8 +541,8 @@ impl<'a> PathSource<'a> {
530
541
__diagnostic_used ! ( E0577 ) ;
531
542
__diagnostic_used ! ( E0578 ) ;
532
543
match ( self , has_unexpected_resolution) {
533
- ( PathSource :: Trait , true ) => "E0404" ,
534
- ( PathSource :: Trait , false ) => "E0405" ,
544
+ ( PathSource :: Trait ( _ ) , true ) => "E0404" ,
545
+ ( PathSource :: Trait ( _ ) , false ) => "E0405" ,
535
546
( PathSource :: Type , true ) => "E0573" ,
536
547
( PathSource :: Type , false ) => "E0412" ,
537
548
( PathSource :: Struct , true ) => "E0574" ,
@@ -693,7 +704,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
693
704
tref : & ' tcx ast:: PolyTraitRef ,
694
705
m : & ' tcx ast:: TraitBoundModifier ) {
695
706
self . smart_resolve_path ( tref. trait_ref . ref_id , None ,
696
- & tref. trait_ref . path , PathSource :: Trait ) ;
707
+ & tref. trait_ref . path , PathSource :: Trait ( AliasPossibility :: Maybe ) ) ;
697
708
visit:: walk_poly_trait_ref ( self , tref, m) ;
698
709
}
699
710
fn visit_variant ( & mut self ,
@@ -1935,6 +1946,17 @@ impl<'a> Resolver<'a> {
1935
1946
} ) ;
1936
1947
}
1937
1948
1949
+ ItemKind :: TraitAlias ( ref generics, ref bounds) => {
1950
+ // Create a new rib for the trait-wide type parameters.
1951
+ self . with_type_parameter_rib ( HasTypeParameters ( generics, ItemRibKind ) , |this| {
1952
+ let local_def_id = this. definitions . local_def_id ( item. id ) ;
1953
+ this. with_self_rib ( Def :: SelfTy ( Some ( local_def_id) , None ) , |this| {
1954
+ this. visit_generics ( generics) ;
1955
+ walk_list ! ( this, visit_ty_param_bound, bounds) ;
1956
+ } ) ;
1957
+ } ) ;
1958
+ }
1959
+
1938
1960
ItemKind :: Mod ( _) | ItemKind :: ForeignMod ( _) => {
1939
1961
self . with_scope ( item. id , |this| {
1940
1962
visit:: walk_item ( this, item) ;
@@ -2083,7 +2105,7 @@ impl<'a> Resolver<'a> {
2083
2105
& path,
2084
2106
trait_ref. path . span ,
2085
2107
trait_ref. path . segments . last ( ) . unwrap ( ) . span ,
2086
- PathSource :: Trait )
2108
+ PathSource :: Trait ( AliasPossibility :: No ) )
2087
2109
. base_def ( ) ;
2088
2110
if def != Def :: Err {
2089
2111
new_id = Some ( def. def_id ( ) ) ;
@@ -2635,7 +2657,7 @@ impl<'a> Resolver<'a> {
2635
2657
err. span_label ( span, format ! ( "did you mean `{}!(...)`?" , path_str) ) ;
2636
2658
return ( err, candidates) ;
2637
2659
}
2638
- ( Def :: TyAlias ( ..) , PathSource :: Trait ) => {
2660
+ ( Def :: TyAlias ( ..) , PathSource :: Trait ( _ ) ) => {
2639
2661
err. span_label ( span, "type aliases cannot be used for traits" ) ;
2640
2662
return ( err, candidates) ;
2641
2663
}
0 commit comments