@@ -1624,7 +1624,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1624
1624
1625
1625
/// Lower a qualified path to a type.
1626
1626
#[ instrument( level = "debug" , skip_all) ]
1627
- fn lower_qpath (
1627
+ fn lower_qpath_ty (
1628
1628
& self ,
1629
1629
span : Span ,
1630
1630
opt_self_ty : Option < Ty < ' tcx > > ,
@@ -1642,14 +1642,64 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1642
1642
} ;
1643
1643
debug ! ( ?self_ty) ;
1644
1644
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 > ) {
1645
1695
let trait_ref =
1646
1696
self . lower_mono_trait_ref ( span, trait_def_id, self_ty, trait_segment, false ) ;
1647
1697
debug ! ( ?trait_ref) ;
1648
1698
1649
1699
let item_args =
1650
1700
self . lower_generic_args_of_assoc_item ( span, item_def_id, item_segment, trait_ref. args ) ;
1651
1701
1652
- Ty :: new_projection_from_args ( tcx , item_def_id, item_args)
1702
+ ( item_def_id, item_args)
1653
1703
}
1654
1704
1655
1705
fn error_missing_qpath_self_ty (
@@ -2000,7 +2050,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2000
2050
path. segments [ ..path. segments . len ( ) - 2 ] . iter ( ) ,
2001
2051
GenericsArgsErrExtend :: None ,
2002
2052
) ;
2003
- self . lower_qpath (
2053
+ self . lower_qpath_ty (
2004
2054
span,
2005
2055
opt_self_ty,
2006
2056
def_id,
@@ -2165,6 +2215,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2165
2215
) ;
2166
2216
ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2167
2217
}
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
+ }
2168
2234
Res :: Def ( DefKind :: Static { .. } , _) => {
2169
2235
span_bug ! ( span, "use of bare `static` ConstArgKind::Path's not yet supported" )
2170
2236
}
@@ -2177,7 +2243,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2177
2243
2178
2244
// Exhaustive match to be clear about what exactly we're considering to be
2179
2245
// an invalid Res for a const path.
2180
- Res :: Def (
2246
+ res @ ( Res :: Def (
2181
2247
DefKind :: Mod
2182
2248
| DefKind :: Enum
2183
2249
| DefKind :: Variant
@@ -2191,7 +2257,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2191
2257
| DefKind :: Union
2192
2258
| DefKind :: Trait
2193
2259
| DefKind :: ForeignTy
2194
- | DefKind :: AssocConst
2195
2260
| DefKind :: TyParam
2196
2261
| DefKind :: Macro ( _)
2197
2262
| DefKind :: LifetimeParam
@@ -2214,7 +2279,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2214
2279
| Res :: Local ( _)
2215
2280
| Res :: ToolMod
2216
2281
| 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
+ ) ,
2218
2287
}
2219
2288
}
2220
2289
0 commit comments