@@ -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,7 +478,11 @@ 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 {
482
+ Def :: Trait ( ..) => true ,
483
+ _ => false ,
484
+ } ,
485
+ PathSource :: Trait ( AliasPossibility :: Maybe ) => match def {
476
486
Def :: Trait ( ..) => true ,
477
487
Def :: TraitAlias ( ..) => true ,
478
488
_ => false ,
@@ -531,8 +541,8 @@ impl<'a> PathSource<'a> {
531
541
__diagnostic_used ! ( E0577 ) ;
532
542
__diagnostic_used ! ( E0578 ) ;
533
543
match ( self , has_unexpected_resolution) {
534
- ( PathSource :: Trait , true ) => "E0404" ,
535
- ( PathSource :: Trait , false ) => "E0405" ,
544
+ ( PathSource :: Trait ( _ ) , true ) => "E0404" ,
545
+ ( PathSource :: Trait ( _ ) , false ) => "E0405" ,
536
546
( PathSource :: Type , true ) => "E0573" ,
537
547
( PathSource :: Type , false ) => "E0412" ,
538
548
( PathSource :: Struct , true ) => "E0574" ,
@@ -694,7 +704,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
694
704
tref : & ' tcx ast:: PolyTraitRef ,
695
705
m : & ' tcx ast:: TraitBoundModifier ) {
696
706
self . smart_resolve_path ( tref. trait_ref . ref_id , None ,
697
- & tref. trait_ref . path , PathSource :: Trait ) ;
707
+ & tref. trait_ref . path , PathSource :: Trait ( AliasPossibility :: Maybe ) ) ;
698
708
visit:: walk_poly_trait_ref ( self , tref, m) ;
699
709
}
700
710
fn visit_variant ( & mut self ,
@@ -2095,7 +2105,7 @@ impl<'a> Resolver<'a> {
2095
2105
& path,
2096
2106
trait_ref. path . span ,
2097
2107
trait_ref. path . segments . last ( ) . unwrap ( ) . span ,
2098
- PathSource :: Trait )
2108
+ PathSource :: Trait ( AliasPossibility :: No ) )
2099
2109
. base_def ( ) ;
2100
2110
if def != Def :: Err {
2101
2111
new_id = Some ( def. def_id ( ) ) ;
@@ -2647,7 +2657,7 @@ impl<'a> Resolver<'a> {
2647
2657
err. span_label ( span, format ! ( "did you mean `{}!(...)`?" , path_str) ) ;
2648
2658
return ( err, candidates) ;
2649
2659
}
2650
- ( Def :: TyAlias ( ..) , PathSource :: Trait ) => {
2660
+ ( Def :: TyAlias ( ..) , PathSource :: Trait ( _ ) ) => {
2651
2661
err. span_label ( span, "type aliases cannot be used for traits" ) ;
2652
2662
return ( err, candidates) ;
2653
2663
}
0 commit comments