@@ -288,6 +288,20 @@ impl LowerTypeRelativePathMode {
288288 Self :: Const => PermitVariants :: No ,
289289 }
290290 }
291+
292+ fn inherent_alias_term_kind < ' tcx > ( self , def_id : DefId ) -> ty:: AliasTermKind < ' tcx > {
293+ match self {
294+ Self :: Type ( _) => ty:: AliasTermKind :: InherentTy { def_id } ,
295+ Self :: Const => ty:: AliasTermKind :: InherentConst { def_id } ,
296+ }
297+ }
298+
299+ fn projection_alias_term_kind < ' tcx > ( self , def_id : DefId ) -> ty:: AliasTermKind < ' tcx > {
300+ match self {
301+ Self :: Type ( _) => ty:: AliasTermKind :: ProjectionTy { def_id } ,
302+ Self :: Const => ty:: AliasTermKind :: ProjectionConst { def_id } ,
303+ }
304+ }
291305}
292306
293307/// Whether to permit a path to resolve to an enum variant.
@@ -299,7 +313,7 @@ pub enum PermitVariants {
299313
300314#[ derive( Debug , Clone , Copy ) ]
301315enum TypeRelativePath < ' tcx > {
302- AssocItem ( DefId , GenericArgsRef < ' tcx > ) ,
316+ AssocItem ( ty :: AliasTermKind < ' tcx > , GenericArgsRef < ' tcx > ) ,
303317 Variant { adt : Ty < ' tcx > , variant_did : DefId } ,
304318 Ctor { ctor_def_id : DefId , args : GenericArgsRef < ' tcx > } ,
305319}
@@ -1476,12 +1490,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14761490 span,
14771491 LowerTypeRelativePathMode :: Type ( permit_variants) ,
14781492 ) ? {
1479- TypeRelativePath :: AssocItem ( def_id, args) => {
1480- let alias_ty = ty:: AliasTy :: new_from_args (
1481- tcx,
1482- ty:: AliasTyKind :: new_from_def_id ( tcx, def_id) ,
1483- args,
1484- ) ;
1493+ TypeRelativePath :: AssocItem ( kind, args) => {
1494+ let def_id = kind. def_id ( ) ;
1495+ let alias_ty_kind = match kind {
1496+ ty:: AliasTermKind :: ProjectionTy { def_id } => ty:: Projection { def_id } ,
1497+ ty:: AliasTermKind :: InherentTy { def_id } => ty:: Inherent { def_id } ,
1498+ ty:: AliasTermKind :: OpaqueTy { .. }
1499+ | ty:: AliasTermKind :: FreeTy { .. }
1500+ | ty:: AliasTermKind :: ProjectionConst { .. }
1501+ | ty:: AliasTermKind :: InherentConst { .. }
1502+ | ty:: AliasTermKind :: FreeConst { .. }
1503+ | ty:: AliasTermKind :: UnevaluatedConst { .. } => {
1504+ unreachable ! ( )
1505+ }
1506+ } ;
1507+ let alias_ty = ty:: AliasTy :: new_from_args ( tcx, alias_ty_kind, args) ;
14851508 let ty = Ty :: new_alias ( tcx, alias_ty) ;
14861509 let ty = self . check_param_uses_if_mcg ( ty, span, false ) ;
14871510 Ok ( ( ty, tcx. def_kind ( def_id) , def_id) )
@@ -1516,12 +1539,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15161539 span,
15171540 LowerTypeRelativePathMode :: Const ,
15181541 ) ? {
1519- TypeRelativePath :: AssocItem ( def_id, args) => {
1520- self . require_type_const_attribute ( def_id, span) ?;
1521- let ct = Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( def_id, args) ) ;
1522- let ct = self . check_param_uses_if_mcg ( ct, span, false ) ;
1523- Ok ( ct)
1524- }
1542+ TypeRelativePath :: AssocItem ( kind, args) => match kind {
1543+ ty:: AliasTermKind :: ProjectionConst { def_id }
1544+ | ty:: AliasTermKind :: InherentConst { def_id } => {
1545+ self . require_type_const_attribute ( def_id, span) ?;
1546+ let ct = Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( def_id, args) ) ;
1547+ let ct = self . check_param_uses_if_mcg ( ct, span, false ) ;
1548+ Ok ( ct)
1549+ }
1550+ ty:: AliasTermKind :: ProjectionTy { .. }
1551+ | ty:: AliasTermKind :: InherentTy { .. }
1552+ | ty:: AliasTermKind :: OpaqueTy { .. }
1553+ | ty:: AliasTermKind :: FreeTy { .. }
1554+ | ty:: AliasTermKind :: UnevaluatedConst { .. }
1555+ | ty:: AliasTermKind :: FreeConst { .. } => span_bug ! (
1556+ span,
1557+ "type-relative const path should only produce \
1558+ ProjectionConst or InherentConst, got {kind:?}"
1559+ ) ,
1560+ } ,
15251561 TypeRelativePath :: Ctor { ctor_def_id, args } => match tcx. def_kind ( ctor_def_id) {
15261562 DefKind :: Ctor ( _, CtorKind :: Fn ) => {
15271563 Ok ( ty:: Const :: zero_sized ( tcx, Ty :: new_fn_def ( tcx, ctor_def_id, args) ) )
@@ -1648,15 +1684,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16481684 }
16491685
16501686 // FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
1651- if let Some ( ( did , args) ) = self . probe_inherent_assoc_item (
1687+ if let Some ( ( def_id , args) ) = self . probe_inherent_assoc_item (
16521688 segment,
16531689 adt_def. did ( ) ,
16541690 self_ty,
16551691 qpath_hir_id,
16561692 span,
16571693 mode. assoc_tag ( ) ,
16581694 ) ? {
1659- return Ok ( TypeRelativePath :: AssocItem ( did, args) ) ;
1695+ return Ok ( TypeRelativePath :: AssocItem (
1696+ mode. inherent_alias_term_kind ( def_id) ,
1697+ args,
1698+ ) ) ;
16601699 }
16611700 }
16621701
@@ -1690,7 +1729,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16901729 ) ;
16911730 }
16921731
1693- Ok ( TypeRelativePath :: AssocItem ( item_def_id, args) )
1732+ Ok ( TypeRelativePath :: AssocItem ( mode . projection_alias_term_kind ( item_def_id) , args) )
16941733 }
16951734
16961735 /// Resolve a [type-relative](hir::QPath::TypeRelative) (and type-level) path.
0 commit comments