@@ -390,12 +390,18 @@ impl PatternSource {
390390 }
391391}
392392
393+ #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
394+ enum AliasPossibility {
395+ No ,
396+ Maybe ,
397+ }
398+
393399#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
394400enum PathSource < ' a > {
395401 // Type paths `Path`.
396402 Type ,
397403 // Trait paths in bounds or impls.
398- Trait ,
404+ Trait ( AliasPossibility ) ,
399405 // Expression paths `path`, with optional parent context.
400406 Expr ( Option < & ' a Expr > ) ,
401407 // Paths in path patterns `Path`.
@@ -415,7 +421,7 @@ enum PathSource<'a> {
415421impl < ' a > PathSource < ' a > {
416422 fn namespace ( self ) -> Namespace {
417423 match self {
418- PathSource :: Type | PathSource :: Trait | PathSource :: Struct |
424+ PathSource :: Type | PathSource :: Trait ( _ ) | PathSource :: Struct |
419425 PathSource :: Visibility | PathSource :: ImportPrefix => TypeNS ,
420426 PathSource :: Expr ( ..) | PathSource :: Pat | PathSource :: TupleStruct => ValueNS ,
421427 PathSource :: TraitItem ( ns) => ns,
@@ -427,23 +433,23 @@ impl<'a> PathSource<'a> {
427433 PathSource :: Visibility | PathSource :: ImportPrefix => true ,
428434 PathSource :: Type | PathSource :: Expr ( ..) | PathSource :: Pat |
429435 PathSource :: Struct | PathSource :: TupleStruct |
430- PathSource :: Trait | PathSource :: TraitItem ( ..) => false ,
436+ PathSource :: Trait ( _ ) | PathSource :: TraitItem ( ..) => false ,
431437 }
432438 }
433439
434440 fn defer_to_typeck ( self ) -> bool {
435441 match self {
436442 PathSource :: Type | PathSource :: Expr ( ..) | PathSource :: Pat |
437443 PathSource :: Struct | PathSource :: TupleStruct => true ,
438- PathSource :: Trait | PathSource :: TraitItem ( ..) |
444+ PathSource :: Trait ( _ ) | PathSource :: TraitItem ( ..) |
439445 PathSource :: Visibility | PathSource :: ImportPrefix => false ,
440446 }
441447 }
442448
443449 fn descr_expected ( self ) -> & ' static str {
444450 match self {
445451 PathSource :: Type => "type" ,
446- PathSource :: Trait => "trait" ,
452+ PathSource :: Trait ( _ ) => "trait" ,
447453 PathSource :: Pat => "unit struct/variant or constant" ,
448454 PathSource :: Struct => "struct, variant or union type" ,
449455 PathSource :: TupleStruct => "tuple struct/variant" ,
@@ -472,7 +478,11 @@ impl<'a> PathSource<'a> {
472478 Def :: TyForeign ( ..) => true ,
473479 _ => false ,
474480 } ,
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 {
476486 Def :: Trait ( ..) => true ,
477487 Def :: TraitAlias ( ..) => true ,
478488 _ => false ,
@@ -531,8 +541,8 @@ impl<'a> PathSource<'a> {
531541 __diagnostic_used ! ( E0577 ) ;
532542 __diagnostic_used ! ( E0578 ) ;
533543 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" ,
536546 ( PathSource :: Type , true ) => "E0573" ,
537547 ( PathSource :: Type , false ) => "E0412" ,
538548 ( PathSource :: Struct , true ) => "E0574" ,
@@ -694,7 +704,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
694704 tref : & ' tcx ast:: PolyTraitRef ,
695705 m : & ' tcx ast:: TraitBoundModifier ) {
696706 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 ) ) ;
698708 visit:: walk_poly_trait_ref ( self , tref, m) ;
699709 }
700710 fn visit_variant ( & mut self ,
@@ -2095,7 +2105,7 @@ impl<'a> Resolver<'a> {
20952105 & path,
20962106 trait_ref. path . span ,
20972107 trait_ref. path . segments . last ( ) . unwrap ( ) . span ,
2098- PathSource :: Trait )
2108+ PathSource :: Trait ( AliasPossibility :: No ) )
20992109 . base_def ( ) ;
21002110 if def != Def :: Err {
21012111 new_id = Some ( def. def_id ( ) ) ;
@@ -2647,7 +2657,7 @@ impl<'a> Resolver<'a> {
26472657 err. span_label ( span, format ! ( "did you mean `{}!(...)`?" , path_str) ) ;
26482658 return ( err, candidates) ;
26492659 }
2650- ( Def :: TyAlias ( ..) , PathSource :: Trait ) => {
2660+ ( Def :: TyAlias ( ..) , PathSource :: Trait ( _ ) ) => {
26512661 err. span_label ( span, "type aliases cannot be used for traits" ) ;
26522662 return ( err, candidates) ;
26532663 }
0 commit comments