@@ -245,35 +245,42 @@ pub enum FeedConstTy<'a, 'tcx> {
245
245
246
246
#[ derive( Debug , Clone , Copy ) ]
247
247
enum LowerTypeRelativePathMode {
248
- Type { permit_variants : bool } ,
248
+ Type ( PermitVariants ) ,
249
249
Const ,
250
250
}
251
251
252
252
impl LowerTypeRelativePathMode {
253
253
fn assoc_tag ( self ) -> ty:: AssocTag {
254
254
match self {
255
- Self :: Type { .. } => ty:: AssocTag :: Type ,
255
+ Self :: Type ( _ ) => ty:: AssocTag :: Type ,
256
256
Self :: Const => ty:: AssocTag :: Const ,
257
257
}
258
258
}
259
259
260
260
fn def_kind ( self ) -> DefKind {
261
261
match self {
262
- Self :: Type { .. } => DefKind :: AssocTy ,
262
+ Self :: Type ( _ ) => DefKind :: AssocTy ,
263
263
Self :: Const => DefKind :: AssocConst ,
264
264
}
265
265
}
266
266
267
- fn permit_variants ( self ) -> bool {
267
+ fn permit_variants ( self ) -> PermitVariants {
268
268
match self {
269
- Self :: Type { permit_variants } => permit_variants,
269
+ Self :: Type ( permit_variants) => permit_variants,
270
270
// FIXME(mgca): Support paths like `Option::<T>::None` or `Option::<T>::Some` which
271
271
// resolve to const ctors/fn items respectively.
272
- Self :: Const => false ,
272
+ Self :: Const => PermitVariants :: No ,
273
273
}
274
274
}
275
275
}
276
276
277
+ /// Whether to permit a path to resolve to an enum variant.
278
+ #[ derive( Debug , Clone , Copy ) ]
279
+ pub enum PermitVariants {
280
+ Yes ,
281
+ No ,
282
+ }
283
+
277
284
#[ derive( Debug , Clone , Copy ) ]
278
285
enum TypeRelativePath < ' tcx > {
279
286
AssocItem ( DefId , GenericArgsRef < ' tcx > ) ,
@@ -1160,7 +1167,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1160
1167
segment : & ' tcx hir:: PathSegment < ' tcx > ,
1161
1168
qpath_hir_id : HirId ,
1162
1169
span : Span ,
1163
- permit_variants : bool ,
1170
+ permit_variants : PermitVariants ,
1164
1171
) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
1165
1172
let tcx = self . tcx ( ) ;
1166
1173
match self . lower_type_relative_path (
@@ -1169,7 +1176,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1169
1176
segment,
1170
1177
qpath_hir_id,
1171
1178
span,
1172
- LowerTypeRelativePathMode :: Type { permit_variants } ,
1179
+ LowerTypeRelativePathMode :: Type ( permit_variants) ,
1173
1180
) ? {
1174
1181
TypeRelativePath :: AssocItem ( def_id, args) => {
1175
1182
let alias_ty = ty:: AliasTy :: new_from_args ( tcx, def_id, args) ;
@@ -1245,7 +1252,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1245
1252
. iter ( )
1246
1253
. find ( |vd| tcx. hygienic_eq ( ident, vd. ident ( tcx) , adt_def. did ( ) ) ) ;
1247
1254
if let Some ( variant_def) = variant_def {
1248
- if mode. permit_variants ( ) {
1255
+ if let PermitVariants :: Yes = mode. permit_variants ( ) {
1249
1256
tcx. check_stability ( variant_def. def_id , Some ( qpath_hir_id) , span, None ) ;
1250
1257
let _ = self . prohibit_generic_args (
1251
1258
slice:: from_ref ( segment) . iter ( ) ,
@@ -2072,7 +2079,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2072
2079
opt_self_ty : Option < Ty < ' tcx > > ,
2073
2080
path : & hir:: Path < ' tcx > ,
2074
2081
hir_id : HirId ,
2075
- permit_variants : bool ,
2082
+ permit_variants : PermitVariants ,
2076
2083
) -> Ty < ' tcx > {
2077
2084
debug ! ( ?path. res, ?opt_self_ty, ?path. segments) ;
2078
2085
let tcx = self . tcx ( ) ;
@@ -2103,7 +2110,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2103
2110
) ;
2104
2111
self . lower_path_segment ( span, did, path. segments . last ( ) . unwrap ( ) )
2105
2112
}
2106
- Res :: Def ( kind @ DefKind :: Variant , def_id) if permit_variants => {
2113
+ Res :: Def ( kind @ DefKind :: Variant , def_id)
2114
+ if let PermitVariants :: Yes = permit_variants =>
2115
+ {
2107
2116
// Lower "variant type" as if it were a real type.
2108
2117
// The resulting `Ty` is type of the variant's enum for now.
2109
2118
assert_eq ! ( opt_self_ty, None ) ;
@@ -2633,7 +2642,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2633
2642
hir:: TyKind :: Path ( hir:: QPath :: Resolved ( maybe_qself, path) ) => {
2634
2643
debug ! ( ?maybe_qself, ?path) ;
2635
2644
let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2636
- self . lower_resolved_ty_path ( opt_self_ty, path, hir_ty. hir_id , false )
2645
+ self . lower_resolved_ty_path ( opt_self_ty, path, hir_ty. hir_id , PermitVariants :: No )
2637
2646
}
2638
2647
& hir:: TyKind :: OpaqueDef ( opaque_ty) => {
2639
2648
// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
@@ -2696,7 +2705,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2696
2705
segment,
2697
2706
hir_ty. hir_id ,
2698
2707
hir_ty. span ,
2699
- false ,
2708
+ PermitVariants :: No ,
2700
2709
)
2701
2710
. map ( |( ty, _, _) | ty)
2702
2711
. unwrap_or_else ( |guar| Ty :: new_error ( tcx, guar) )
0 commit comments