@@ -1624,7 +1624,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16241624
16251625 /// Lower a qualified path to a type.
16261626 #[ instrument( level = "debug" , skip_all) ]
1627- fn lower_qpath (
1627+ fn lower_qpath_ty (
16281628 & self ,
16291629 span : Span ,
16301630 opt_self_ty : Option < Ty < ' tcx > > ,
@@ -1642,14 +1642,64 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16421642 } ;
16431643 debug ! ( ?self_ty) ;
16441644
1645+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1646+ span,
1647+ self_ty,
1648+ trait_def_id,
1649+ item_def_id,
1650+ trait_segment,
1651+ item_segment,
1652+ ) ;
1653+ Ty :: new_projection_from_args ( tcx, item_def_id, item_args)
1654+ }
1655+
1656+ /// Lower a qualified path to a const.
1657+ #[ instrument( level = "debug" , skip_all) ]
1658+ fn lower_qpath_const (
1659+ & self ,
1660+ span : Span ,
1661+ self_ty : Ty < ' tcx > ,
1662+ item_def_id : DefId ,
1663+ trait_segment : & hir:: PathSegment < ' tcx > ,
1664+ item_segment : & hir:: PathSegment < ' tcx > ,
1665+ ) -> Const < ' tcx > {
1666+ let tcx = self . tcx ( ) ;
1667+
1668+ let trait_def_id = tcx. parent ( item_def_id) ;
1669+ debug ! ( ?trait_def_id) ;
1670+
1671+ debug ! ( ?self_ty) ;
1672+
1673+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1674+ span,
1675+ self_ty,
1676+ trait_def_id,
1677+ item_def_id,
1678+ trait_segment,
1679+ item_segment,
1680+ ) ;
1681+ let uv = ty:: UnevaluatedConst :: new ( item_def_id, item_args) ;
1682+ Const :: new_unevaluated ( tcx, uv)
1683+ }
1684+
1685+ #[ instrument( level = "debug" , skip_all) ]
1686+ fn lower_qpath_shared (
1687+ & self ,
1688+ span : Span ,
1689+ self_ty : Ty < ' tcx > ,
1690+ trait_def_id : DefId ,
1691+ item_def_id : DefId ,
1692+ trait_segment : & hir:: PathSegment < ' tcx > ,
1693+ item_segment : & hir:: PathSegment < ' tcx > ,
1694+ ) -> ( DefId , GenericArgsRef < ' tcx > ) {
16451695 let trait_ref =
16461696 self . lower_mono_trait_ref ( span, trait_def_id, self_ty, trait_segment, false ) ;
16471697 debug ! ( ?trait_ref) ;
16481698
16491699 let item_args =
16501700 self . lower_generic_args_of_assoc_item ( span, item_def_id, item_segment, trait_ref. args ) ;
16511701
1652- Ty :: new_projection_from_args ( tcx , item_def_id, item_args)
1702+ ( item_def_id, item_args)
16531703 }
16541704
16551705 fn error_missing_qpath_self_ty (
@@ -2000,7 +2050,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20002050 path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
20012051 GenericsArgsErrExtend :: None ,
20022052 ) ;
2003- self . lower_qpath (
2053+ self . lower_qpath_ty (
20042054 span,
20052055 opt_self_ty,
20062056 def_id,
@@ -2165,6 +2215,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21652215 ) ;
21662216 ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
21672217 }
2218+ Res :: Def ( DefKind :: AssocConst , did) => {
2219+ debug_assert ! ( path. segments. len( ) >= 2 ) ;
2220+ let _ = self . prohibit_generic_args (
2221+ path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
2222+ GenericsArgsErrExtend :: None ,
2223+ ) ;
2224+ // FIXME(mgca): maybe needs proper error reported
2225+ let Some ( self_ty) = opt_self_ty else { span_bug ! ( span, "{path:?}" ) } ;
2226+ self . lower_qpath_const (
2227+ span,
2228+ self_ty,
2229+ did,
2230+ & path. segments [ path. segments . len ( ) - 2 ] ,
2231+ path. segments . last ( ) . unwrap ( ) ,
2232+ )
2233+ }
21682234 Res :: Def ( DefKind :: Static { .. } , _) => {
21692235 span_bug ! ( span, "use of bare `static` ConstArgKind::Path's not yet supported" )
21702236 }
@@ -2177,7 +2243,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21772243
21782244 // Exhaustive match to be clear about what exactly we're considering to be
21792245 // an invalid Res for a const path.
2180- Res :: Def (
2246+ res @ ( Res :: Def (
21812247 DefKind :: Mod
21822248 | DefKind :: Enum
21832249 | DefKind :: Variant
@@ -2191,7 +2257,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21912257 | DefKind :: Union
21922258 | DefKind :: Trait
21932259 | DefKind :: ForeignTy
2194- | DefKind :: AssocConst
21952260 | DefKind :: TyParam
21962261 | DefKind :: Macro ( _)
21972262 | DefKind :: LifetimeParam
@@ -2214,7 +2279,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22142279 | Res :: Local ( _)
22152280 | Res :: ToolMod
22162281 | Res :: NonMacroAttr ( _)
2217- | Res :: Err => Const :: new_error_with_message ( tcx, span, "invalid Res for const path" ) ,
2282+ | Res :: Err ) => Const :: new_error_with_message (
2283+ tcx,
2284+ span,
2285+ format ! ( "invalid Res {res:?} for const path" ) ,
2286+ ) ,
22182287 }
22192288 }
22202289
0 commit comments