@@ -1288,7 +1288,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
1288
1288
span : Span ,
1289
1289
ty : Ty < ' tcx > ,
1290
1290
ty_path_def : Def ,
1291
- item_segment : & hir:: PathSegment )
1291
+ item_segment : & hir:: PathSegment ,
1292
+ permit_variants : bool )
1292
1293
-> ( Ty < ' tcx > , Def )
1293
1294
{
1294
1295
let tcx = self . tcx ( ) ;
@@ -1298,11 +1299,38 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
1298
1299
1299
1300
self . prohibit_generics ( slice:: from_ref ( item_segment) ) ;
1300
1301
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
+
1301
1329
// Find the type of the associated item, and the trait where the associated
1302
1330
// item is declared.
1303
1331
let bound = match ( & ty. sty , ty_path_def) {
1304
1332
( _, 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
1306
1334
// trait reference.
1307
1335
let trait_ref = match tcx. impl_trait_ref ( impl_def_id) {
1308
1336
Some ( trait_ref) => trait_ref,
@@ -1354,23 +1382,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
1354
1382
return ( tcx. types . err , Def :: Err ) ;
1355
1383
}
1356
1384
_ => {
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
-
1374
1385
// Don't print `TyErr` to the user.
1375
1386
if !ty. references_error ( ) {
1376
1387
self . report_ambiguous_associated_type ( span,
@@ -1773,7 +1784,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
1773
1784
} else {
1774
1785
Def :: Err
1775
1786
} ;
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
1777
1788
}
1778
1789
hir:: TyKind :: Array ( ref ty, ref length) => {
1779
1790
let length_def_id = tcx. hir ( ) . local_def_id ( length. id ) ;
0 commit comments