@@ -1646,7 +1646,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16461646
16471647 /// Lower a qualified path to a type.
16481648 #[ instrument( level = "debug" , skip_all) ]
1649- fn lower_qpath (
1649+ fn lower_qpath_ty (
16501650 & self ,
16511651 span : Span ,
16521652 opt_self_ty : Option < Ty < ' tcx > > ,
@@ -1664,14 +1664,64 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16641664 } ;
16651665 debug ! ( ?self_ty) ;
16661666
1667+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1668+ span,
1669+ self_ty,
1670+ trait_def_id,
1671+ item_def_id,
1672+ trait_segment,
1673+ item_segment,
1674+ ) ;
1675+ Ty :: new_projection_from_args ( tcx, item_def_id, item_args)
1676+ }
1677+
1678+ /// Lower a qualified path to a const.
1679+ #[ instrument( level = "debug" , skip_all) ]
1680+ fn lower_qpath_const (
1681+ & self ,
1682+ span : Span ,
1683+ self_ty : Ty < ' tcx > ,
1684+ item_def_id : DefId ,
1685+ trait_segment : & hir:: PathSegment < ' tcx > ,
1686+ item_segment : & hir:: PathSegment < ' tcx > ,
1687+ ) -> Const < ' tcx > {
1688+ let tcx = self . tcx ( ) ;
1689+
1690+ let trait_def_id = tcx. parent ( item_def_id) ;
1691+ debug ! ( ?trait_def_id) ;
1692+
1693+ debug ! ( ?self_ty) ;
1694+
1695+ let ( item_def_id, item_args) = self . lower_qpath_shared (
1696+ span,
1697+ self_ty,
1698+ trait_def_id,
1699+ item_def_id,
1700+ trait_segment,
1701+ item_segment,
1702+ ) ;
1703+ let uv = ty:: UnevaluatedConst :: new ( item_def_id, item_args) ;
1704+ Const :: new_unevaluated ( tcx, uv)
1705+ }
1706+
1707+ #[ instrument( level = "debug" , skip_all) ]
1708+ fn lower_qpath_shared (
1709+ & self ,
1710+ span : Span ,
1711+ self_ty : Ty < ' tcx > ,
1712+ trait_def_id : DefId ,
1713+ item_def_id : DefId ,
1714+ trait_segment : & hir:: PathSegment < ' tcx > ,
1715+ item_segment : & hir:: PathSegment < ' tcx > ,
1716+ ) -> ( DefId , GenericArgsRef < ' tcx > ) {
16671717 let trait_ref =
16681718 self . lower_mono_trait_ref ( span, trait_def_id, self_ty, trait_segment, false ) ;
16691719 debug ! ( ?trait_ref) ;
16701720
16711721 let item_args =
16721722 self . lower_generic_args_of_assoc_item ( span, item_def_id, item_segment, trait_ref. args ) ;
16731723
1674- Ty :: new_projection_from_args ( tcx , item_def_id, item_args)
1724+ ( item_def_id, item_args)
16751725 }
16761726
16771727 fn error_missing_qpath_self_ty (
@@ -2021,7 +2071,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20212071 path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
20222072 GenericsArgsErrExtend :: None ,
20232073 ) ;
2024- self . lower_qpath (
2074+ self . lower_qpath_ty (
20252075 span,
20262076 opt_self_ty,
20272077 def_id,
@@ -2222,6 +2272,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22222272 ) ;
22232273 ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
22242274 }
2275+ Res :: Def ( DefKind :: AssocConst , did) => {
2276+ debug_assert ! ( path. segments. len( ) >= 2 ) ;
2277+ let _ = self . prohibit_generic_args (
2278+ path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
2279+ GenericsArgsErrExtend :: None ,
2280+ ) ;
2281+ // FIXME(mgca): maybe needs proper error reported
2282+ let Some ( self_ty) = opt_self_ty else { span_bug ! ( span, "{path:?}" ) } ;
2283+ self . lower_qpath_const (
2284+ span,
2285+ self_ty,
2286+ did,
2287+ & path. segments [ path. segments . len ( ) - 2 ] ,
2288+ path. segments . last ( ) . unwrap ( ) ,
2289+ )
2290+ }
22252291 Res :: Def ( DefKind :: Static { .. } , _) => {
22262292 span_bug ! ( span, "use of bare `static` ConstArgKind::Path's not yet supported" )
22272293 }
@@ -2238,7 +2304,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22382304
22392305 // Exhaustive match to be clear about what exactly we're considering to be
22402306 // an invalid Res for a const path.
2241- Res :: Def (
2307+ res @ ( Res :: Def (
22422308 DefKind :: Mod
22432309 | DefKind :: Enum
22442310 | DefKind :: Variant
@@ -2252,7 +2318,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22522318 | DefKind :: Union
22532319 | DefKind :: Trait
22542320 | DefKind :: ForeignTy
2255- | DefKind :: AssocConst
22562321 | DefKind :: TyParam
22572322 | DefKind :: Macro ( _)
22582323 | DefKind :: LifetimeParam
@@ -2275,7 +2340,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22752340 | Res :: Local ( _)
22762341 | Res :: ToolMod
22772342 | Res :: NonMacroAttr ( _)
2278- | Res :: Err => Const :: new_error_with_message ( tcx, span, "invalid Res for const path" ) ,
2343+ | Res :: Err ) => Const :: new_error_with_message (
2344+ tcx,
2345+ span,
2346+ format ! ( "invalid Res {res:?} for const path" ) ,
2347+ ) ,
22792348 }
22802349 }
22812350
0 commit comments