@@ -1288,7 +1288,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12881288 span : Span ,
12891289 ty : Ty < ' tcx > ,
12901290 ty_path_def : Def ,
1291- item_segment : & hir:: PathSegment )
1291+ item_segment : & hir:: PathSegment ,
1292+ permit_variants : bool )
12921293 -> ( Ty < ' tcx > , Def )
12931294 {
12941295 let tcx = self . tcx ( ) ;
@@ -1298,11 +1299,38 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12981299
12991300 self . prohibit_generics ( slice:: from_ref ( item_segment) ) ;
13001301
1302+ // Check if we have an enum variant here.
1303+ match ty. sty {
1304+ ty:: Adt ( adt_def, _) if adt_def. is_enum ( ) => {
1305+ let variant_def = adt_def. variants . iter ( ) . find ( |vd| {
1306+ tcx. hygienic_eq ( assoc_name, vd. ident , adt_def. did )
1307+ } ) ;
1308+ if let Some ( variant_def) = variant_def {
1309+ if permit_variants {
1310+ check_type_alias_enum_variants_enabled ( tcx, span) ;
1311+
1312+ let def = Def :: Variant ( variant_def. did ) ;
1313+ tcx. check_stability ( def. def_id ( ) , Some ( ref_id) , span) ;
1314+ return ( ty, def) ;
1315+ } else {
1316+ use rustc:: lint:: builtin:: TYPE_VS_VARIANT_AMBIGUITY ;
1317+ tcx. lint_node (
1318+ TYPE_VS_VARIANT_AMBIGUITY ,
1319+ ref_id,
1320+ span,
1321+ "type vs variant ambiguity" ,
1322+ ) ;
1323+ }
1324+ }
1325+ } ,
1326+ _ => ( ) ,
1327+ }
1328+
13011329 // Find the type of the associated item, and the trait where the associated
13021330 // item is declared.
13031331 let bound = match ( & ty. sty , ty_path_def) {
13041332 ( _, Def :: SelfTy ( Some ( _) , Some ( impl_def_id) ) ) => {
1305- // `Self` in an impl of a trait -- we have a concrete self type and a
1333+ // `Self` in an impl of a trait -- we have a concrete ` self` type and a
13061334 // trait reference.
13071335 let trait_ref = match tcx. impl_trait_ref ( impl_def_id) {
13081336 Some ( trait_ref) => trait_ref,
@@ -1354,23 +1382,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
13541382 return ( tcx. types . err , Def :: Err ) ;
13551383 }
13561384 _ => {
1357- // Check if we have an enum variant.
1358- match ty. sty {
1359- ty:: Adt ( adt_def, _) if adt_def. is_enum ( ) => {
1360- let variant_def = adt_def. variants . iter ( ) . find ( |vd| {
1361- tcx. hygienic_eq ( assoc_name, vd. ident , adt_def. did )
1362- } ) ;
1363- if let Some ( variant_def) = variant_def {
1364- check_type_alias_enum_variants_enabled ( tcx, span) ;
1365-
1366- let def = Def :: Variant ( variant_def. did ) ;
1367- tcx. check_stability ( def. def_id ( ) , Some ( ref_id) , span) ;
1368- return ( ty, def) ;
1369- }
1370- } ,
1371- _ => ( ) ,
1372- }
1373-
13741385 // Don't print `TyErr` to the user.
13751386 if !ty. references_error ( ) {
13761387 self . report_ambiguous_associated_type ( span,
@@ -1773,7 +1784,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
17731784 } else {
17741785 Def :: Err
17751786 } ;
1776- self . associated_path_def_to_ty ( ast_ty. id , ast_ty. span , ty, def, segment) . 0
1787+ self . associated_path_def_to_ty ( ast_ty. id , ast_ty. span , ty, def, segment, false ) . 0
17771788 }
17781789 hir:: TyKind :: Array ( ref ty, ref length) => {
17791790 let length_def_id = tcx. hir ( ) . local_def_id ( length. id ) ;
0 commit comments