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