@@ -287,6 +287,20 @@ impl LowerTypeRelativePathMode {
287287 Self :: Const => PermitVariants :: No ,
288288 }
289289 }
290+
291+ fn inherent_alias_term_kind ( self ) -> ty:: AliasTermKind {
292+ match self {
293+ Self :: Type ( _) => ty:: AliasTermKind :: InherentTy ,
294+ Self :: Const => ty:: AliasTermKind :: InherentConst ,
295+ }
296+ }
297+
298+ fn projection_alias_term_kind ( self ) -> ty:: AliasTermKind {
299+ match self {
300+ Self :: Type ( _) => ty:: AliasTermKind :: ProjectionTy ,
301+ Self :: Const => ty:: AliasTermKind :: ProjectionConst ,
302+ }
303+ }
290304}
291305
292306/// Whether to permit a path to resolve to an enum variant.
@@ -298,7 +312,7 @@ pub enum PermitVariants {
298312
299313#[ derive( Debug , Clone , Copy ) ]
300314enum TypeRelativePath < ' tcx > {
301- AssocItem ( DefId , GenericArgsRef < ' tcx > ) ,
315+ AssocItem ( ty :: AliasTermKind , DefId , GenericArgsRef < ' tcx > ) ,
302316 Variant { adt : Ty < ' tcx > , variant_did : DefId } ,
303317 Ctor { ctor_def_id : DefId , args : GenericArgsRef < ' tcx > } ,
304318}
@@ -1400,12 +1414,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14001414 span,
14011415 LowerTypeRelativePathMode :: Type ( permit_variants) ,
14021416 ) ? {
1403- TypeRelativePath :: AssocItem ( def_id, args) => {
1404- let alias_ty = ty:: AliasTy :: new_from_args (
1405- tcx,
1406- ty:: AliasTyKind :: new_from_def_id ( tcx, def_id) ,
1407- args,
1408- ) ;
1417+ TypeRelativePath :: AssocItem ( kind, def_id, args) => {
1418+ let alias_ty_kind = match kind {
1419+ ty:: AliasTermKind :: ProjectionTy => ty:: Projection { def_id } ,
1420+ ty:: AliasTermKind :: InherentTy => ty:: Inherent { def_id } ,
1421+ ty:: AliasTermKind :: OpaqueTy
1422+ | ty:: AliasTermKind :: FreeTy
1423+ | ty:: AliasTermKind :: ProjectionConst
1424+ | ty:: AliasTermKind :: InherentConst
1425+ | ty:: AliasTermKind :: FreeConst
1426+ | ty:: AliasTermKind :: UnevaluatedConst => {
1427+ unreachable ! ( )
1428+ }
1429+ } ;
1430+ let alias_ty = ty:: AliasTy :: new_from_args ( tcx, alias_ty_kind, args) ;
14091431 let ty = Ty :: new_alias ( tcx, alias_ty) ;
14101432 let ty = self . check_param_uses_if_mcg ( ty, span, false ) ;
14111433 Ok ( ( ty, tcx. def_kind ( def_id) , def_id) )
@@ -1440,12 +1462,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14401462 span,
14411463 LowerTypeRelativePathMode :: Const ,
14421464 ) ? {
1443- TypeRelativePath :: AssocItem ( def_id, args) => {
1444- self . require_type_const_attribute ( def_id, span) ?;
1445- let ct = Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( def_id, args) ) ;
1446- let ct = self . check_param_uses_if_mcg ( ct, span, false ) ;
1447- Ok ( ct)
1448- }
1465+ TypeRelativePath :: AssocItem ( kind, def_id, args) => match kind {
1466+ ty:: AliasTermKind :: ProjectionConst | ty:: AliasTermKind :: InherentConst => {
1467+ self . require_type_const_attribute ( def_id, span) ?;
1468+ let ct = Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( def_id, args) ) ;
1469+ let ct = self . check_param_uses_if_mcg ( ct, span, false ) ;
1470+ Ok ( ct)
1471+ }
1472+ ty:: AliasTermKind :: ProjectionTy
1473+ | ty:: AliasTermKind :: InherentTy
1474+ | ty:: AliasTermKind :: OpaqueTy
1475+ | ty:: AliasTermKind :: FreeTy
1476+ | ty:: AliasTermKind :: UnevaluatedConst
1477+ | ty:: AliasTermKind :: FreeConst => span_bug ! (
1478+ span,
1479+ "type-relative const path should only produce \
1480+ ProjectionConst or InherentConst, got {kind:?}"
1481+ ) ,
1482+ } ,
14491483 TypeRelativePath :: Ctor { ctor_def_id, args } => match tcx. def_kind ( ctor_def_id) {
14501484 DefKind :: Ctor ( _, CtorKind :: Fn ) => {
14511485 Ok ( ty:: Const :: zero_sized ( tcx, Ty :: new_fn_def ( tcx, ctor_def_id, args) ) )
@@ -1572,15 +1606,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15721606 }
15731607
15741608 // FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
1575- if let Some ( ( did , args) ) = self . probe_inherent_assoc_item (
1609+ if let Some ( ( def_id , args) ) = self . probe_inherent_assoc_item (
15761610 segment,
15771611 adt_def. did ( ) ,
15781612 self_ty,
15791613 qpath_hir_id,
15801614 span,
15811615 mode. assoc_tag ( ) ,
15821616 ) ? {
1583- return Ok ( TypeRelativePath :: AssocItem ( did, args) ) ;
1617+ return Ok ( TypeRelativePath :: AssocItem (
1618+ mode. inherent_alias_term_kind ( ) ,
1619+ def_id,
1620+ args,
1621+ ) ) ;
15841622 }
15851623 }
15861624
@@ -1614,7 +1652,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16141652 ) ;
16151653 }
16161654
1617- Ok ( TypeRelativePath :: AssocItem ( item_def_id, args) )
1655+ Ok ( TypeRelativePath :: AssocItem ( mode . projection_alias_term_kind ( ) , item_def_id, args) )
16181656 }
16191657
16201658 /// Resolve a [type-relative](hir::QPath::TypeRelative) (and type-level) path.
0 commit comments