@@ -245,35 +245,42 @@ pub enum FeedConstTy<'a, 'tcx> {
245245
246246#[ derive( Debug , Clone , Copy ) ]
247247enum LowerTypeRelativePathMode {
248- Type { permit_variants : bool } ,
248+ Type ( PermitVariants ) ,
249249 Const ,
250250}
251251
252252impl LowerTypeRelativePathMode {
253253 fn assoc_tag ( self ) -> ty:: AssocTag {
254254 match self {
255- Self :: Type { .. } => ty:: AssocTag :: Type ,
255+ Self :: Type ( _ ) => ty:: AssocTag :: Type ,
256256 Self :: Const => ty:: AssocTag :: Const ,
257257 }
258258 }
259259
260260 fn def_kind ( self ) -> DefKind {
261261 match self {
262- Self :: Type { .. } => DefKind :: AssocTy ,
262+ Self :: Type ( _ ) => DefKind :: AssocTy ,
263263 Self :: Const => DefKind :: AssocConst ,
264264 }
265265 }
266266
267- fn permit_variants ( self ) -> bool {
267+ fn permit_variants ( self ) -> PermitVariants {
268268 match self {
269- Self :: Type { permit_variants } => permit_variants,
269+ Self :: Type ( permit_variants) => permit_variants,
270270 // FIXME(mgca): Support paths like `Option::<T>::None` or `Option::<T>::Some` which
271271 // resolve to const ctors/fn items respectively.
272- Self :: Const => false ,
272+ Self :: Const => PermitVariants :: No ,
273273 }
274274 }
275275}
276276
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+
277284#[ derive( Debug , Clone , Copy ) ]
278285enum TypeRelativePath < ' tcx > {
279286 AssocItem ( DefId , GenericArgsRef < ' tcx > ) ,
@@ -1160,7 +1167,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11601167 segment : & ' tcx hir:: PathSegment < ' tcx > ,
11611168 qpath_hir_id : HirId ,
11621169 span : Span ,
1163- permit_variants : bool ,
1170+ permit_variants : PermitVariants ,
11641171 ) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
11651172 let tcx = self . tcx ( ) ;
11661173 match self . lower_type_relative_path (
@@ -1169,7 +1176,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11691176 segment,
11701177 qpath_hir_id,
11711178 span,
1172- LowerTypeRelativePathMode :: Type { permit_variants } ,
1179+ LowerTypeRelativePathMode :: Type ( permit_variants) ,
11731180 ) ? {
11741181 TypeRelativePath :: AssocItem ( def_id, args) => {
11751182 let alias_ty = ty:: AliasTy :: new_from_args ( tcx, def_id, args) ;
@@ -1245,7 +1252,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12451252 . iter ( )
12461253 . find ( |vd| tcx. hygienic_eq ( ident, vd. ident ( tcx) , adt_def. did ( ) ) ) ;
12471254 if let Some ( variant_def) = variant_def {
1248- if mode. permit_variants ( ) {
1255+ if let PermitVariants :: Yes = mode. permit_variants ( ) {
12491256 tcx. check_stability ( variant_def. def_id , Some ( qpath_hir_id) , span, None ) ;
12501257 let _ = self . prohibit_generic_args (
12511258 slice:: from_ref ( segment) . iter ( ) ,
@@ -2072,7 +2079,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20722079 opt_self_ty : Option < Ty < ' tcx > > ,
20732080 path : & hir:: Path < ' tcx > ,
20742081 hir_id : HirId ,
2075- permit_variants : bool ,
2082+ permit_variants : PermitVariants ,
20762083 ) -> Ty < ' tcx > {
20772084 debug ! ( ?path. res, ?opt_self_ty, ?path. segments) ;
20782085 let tcx = self . tcx ( ) ;
@@ -2103,7 +2110,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21032110 ) ;
21042111 self . lower_path_segment ( span, did, path. segments . last ( ) . unwrap ( ) )
21052112 }
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+ {
21072116 // Lower "variant type" as if it were a real type.
21082117 // The resulting `Ty` is type of the variant's enum for now.
21092118 assert_eq ! ( opt_self_ty, None ) ;
@@ -2631,7 +2640,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26312640 hir:: TyKind :: Path ( hir:: QPath :: Resolved ( maybe_qself, path) ) => {
26322641 debug ! ( ?maybe_qself, ?path) ;
26332642 let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2634- self . lower_resolved_ty_path ( opt_self_ty, path, hir_ty. hir_id , false )
2643+ self . lower_resolved_ty_path ( opt_self_ty, path, hir_ty. hir_id , PermitVariants :: No )
26352644 }
26362645 & hir:: TyKind :: OpaqueDef ( opaque_ty) => {
26372646 // If this is an RPITIT and we are using the new RPITIT lowering scheme, we
@@ -2694,7 +2703,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26942703 segment,
26952704 hir_ty. hir_id ,
26962705 hir_ty. span ,
2697- false ,
2706+ PermitVariants :: No ,
26982707 )
26992708 . map ( |( ty, _, _) | ty)
27002709 . unwrap_or_else ( |guar| Ty :: new_error ( tcx, guar) )
0 commit comments