@@ -1623,7 +1623,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16231623
16241624 /// Lower a qualified path to a type.
16251625 #[ instrument( level = "debug" , skip_all) ]
1626- fn lower_qpath (
1626+ fn lower_qpath_ty (
16271627 & self ,
16281628 span : Span ,
16291629 opt_self_ty : Option < Ty < ' tcx > > ,
@@ -1641,14 +1641,64 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16411641 } ;
16421642 debug ! ( ?self_ty) ;
16431643
1644+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1645+ span,
1646+ self_ty,
1647+ trait_def_id,
1648+ item_def_id,
1649+ trait_segment,
1650+ item_segment,
1651+ ) ;
1652+ Ty :: new_projection_from_args ( tcx, item_def_id, item_args)
1653+ }
1654+
1655+ /// Lower a qualified path to a const.
1656+ #[ instrument( level = "debug" , skip_all) ]
1657+ fn lower_qpath_const (
1658+ & self ,
1659+ span : Span ,
1660+ self_ty : Ty < ' tcx > ,
1661+ item_def_id : DefId ,
1662+ trait_segment : & hir:: PathSegment < ' tcx > ,
1663+ item_segment : & hir:: PathSegment < ' tcx > ,
1664+ ) -> Const < ' tcx > {
1665+ let tcx = self . tcx ( ) ;
1666+
1667+ let trait_def_id = tcx. parent ( item_def_id) ;
1668+ debug ! ( ?trait_def_id) ;
1669+
1670+ debug ! ( ?self_ty) ;
1671+
1672+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1673+ span,
1674+ self_ty,
1675+ trait_def_id,
1676+ item_def_id,
1677+ trait_segment,
1678+ item_segment,
1679+ ) ;
1680+ let uv = ty:: UnevaluatedConst :: new ( item_def_id, item_args) ;
1681+ Const :: new_unevaluated ( tcx, uv)
1682+ }
1683+
1684+ #[ instrument( level = "debug" , skip_all) ]
1685+ fn lower_qpath_shared (
1686+ & self ,
1687+ span : Span ,
1688+ self_ty : Ty < ' tcx > ,
1689+ trait_def_id : DefId ,
1690+ item_def_id : DefId ,
1691+ trait_segment : & hir:: PathSegment < ' tcx > ,
1692+ item_segment : & hir:: PathSegment < ' tcx > ,
1693+ ) -> ( DefId , GenericArgsRef < ' tcx > ) {
16441694 let trait_ref =
16451695 self . lower_mono_trait_ref ( span, trait_def_id, self_ty, trait_segment, false ) ;
16461696 debug ! ( ?trait_ref) ;
16471697
16481698 let item_args =
16491699 self . lower_generic_args_of_assoc_item ( span, item_def_id, item_segment, trait_ref. args ) ;
16501700
1651- Ty :: new_projection_from_args ( tcx , item_def_id, item_args)
1701+ ( item_def_id, item_args)
16521702 }
16531703
16541704 fn error_missing_qpath_self_ty (
@@ -1999,7 +2049,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19992049 path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
20002050 GenericsArgsErrExtend :: None ,
20012051 ) ;
2002- self . lower_qpath (
2052+ self . lower_qpath_ty (
20032053 span,
20042054 opt_self_ty,
20052055 def_id,
@@ -2164,6 +2214,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21642214 ) ;
21652215 ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
21662216 }
2217+ Res :: Def ( DefKind :: AssocConst , did) => {
2218+ debug_assert ! ( path. segments. len( ) >= 2 ) ;
2219+ let _ = self . prohibit_generic_args (
2220+ path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
2221+ GenericsArgsErrExtend :: None ,
2222+ ) ;
2223+ // FIXME(mgca): maybe needs proper error reported
2224+ let Some ( self_ty) = opt_self_ty else { span_bug ! ( span, "{path:?}" ) } ;
2225+ self . lower_qpath_const (
2226+ span,
2227+ self_ty,
2228+ did,
2229+ & path. segments [ path. segments . len ( ) - 2 ] ,
2230+ path. segments . last ( ) . unwrap ( ) ,
2231+ )
2232+ }
21672233 Res :: Def ( DefKind :: Static { .. } , _) => {
21682234 span_bug ! ( span, "use of bare `static` ConstArgKind::Path's not yet supported" )
21692235 }
@@ -2176,7 +2242,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21762242
21772243 // Exhaustive match to be clear about what exactly we're considering to be
21782244 // an invalid Res for a const path.
2179- Res :: Def (
2245+ res @ ( Res :: Def (
21802246 DefKind :: Mod
21812247 | DefKind :: Enum
21822248 | DefKind :: Variant
@@ -2190,7 +2256,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21902256 | DefKind :: Union
21912257 | DefKind :: Trait
21922258 | DefKind :: ForeignTy
2193- | DefKind :: AssocConst
21942259 | DefKind :: TyParam
21952260 | DefKind :: Macro ( _)
21962261 | DefKind :: LifetimeParam
@@ -2213,7 +2278,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22132278 | Res :: Local ( _)
22142279 | Res :: ToolMod
22152280 | Res :: NonMacroAttr ( _)
2216- | Res :: Err => Const :: new_error_with_message ( tcx, span, "invalid Res for const path" ) ,
2281+ | Res :: Err ) => Const :: new_error_with_message (
2282+ tcx,
2283+ span,
2284+ format ! ( "invalid Res {res:?} for const path" ) ,
2285+ ) ,
22172286 }
22182287 }
22192288
0 commit comments