@@ -2018,23 +2018,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2018
2018
///
2019
2019
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
2020
2020
/// and late-bound ones to [`ty::ConstKind::Bound`].
2021
- pub ( crate ) fn lower_const_param ( & self , hir_id : HirId ) -> Const < ' tcx > {
2021
+ pub ( crate ) fn lower_const_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
2022
2022
let tcx = self . tcx ( ) ;
2023
- match tcx. named_bound_var ( hir_id) {
2024
- Some ( rbv:: ResolvedArg :: EarlyBound ( def_id) ) => {
2023
+
2024
+ match tcx. named_bound_var ( path_hir_id) {
2025
+ Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
2025
2026
// Find the name and index of the const parameter by indexing the generics of
2026
2027
// the parent item and construct a `ParamConst`.
2027
- let item_def_id = tcx. local_parent ( def_id ) ;
2028
+ let item_def_id = tcx. parent ( param_def_id ) ;
2028
2029
let generics = tcx. generics_of ( item_def_id) ;
2029
- let index = generics. param_def_id_to_index [ & def_id . to_def_id ( ) ] ;
2030
- let name = tcx. item_name ( def_id . to_def_id ( ) ) ;
2030
+ let index = generics. param_def_id_to_index [ & param_def_id ] ;
2031
+ let name = tcx. item_name ( param_def_id ) ;
2031
2032
ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
2032
2033
}
2033
2034
Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
2034
2035
ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
2035
2036
}
2036
2037
Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2037
- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , hir_id ) ,
2038
+ arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id ) ,
2038
2039
}
2039
2040
}
2040
2041
@@ -2063,10 +2064,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2063
2064
fn lower_const_arg_path ( & self , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Const < ' tcx > {
2064
2065
let tcx = self . tcx ( ) ;
2065
2066
2066
- // TODO: handle path args properly
2067
2067
match qpath {
2068
2068
hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , did) , .. } ) => {
2069
- self . lower_const_arg_param ( did, hir_id)
2069
+ self . lower_const_param ( did, hir_id)
2070
2070
}
2071
2071
hir:: QPath :: Resolved (
2072
2072
_,
@@ -2076,31 +2076,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2076
2076
qpath. span ( ) ,
2077
2077
"fn's cannot be used as const args" ,
2078
2078
) ,
2079
- // hir::QPath::Resolved(_, path @ &hir::Path { res: Res::Def(_, did), .. }) => {
2080
- // let (item_segment, _) = path.segments.split_last().unwrap();
2081
- // let args = self.lower_generic_args_of_path_segment(path.span, did, item_segment);
2082
- // ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
2083
- // }
2084
- // // TODO: type-relative paths
2085
- // _ => ty::Const::new_error_with_message(
2086
- // tcx,
2087
- // qpath.span(),
2088
- // "Const::lower_const_arg_path: invalid qpath",
2089
- // ),
2090
2079
hir:: QPath :: Resolved ( maybe_qself, path) => {
2091
2080
debug ! ( ?maybe_qself, ?path) ;
2092
2081
let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2093
2082
self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
2094
2083
}
2095
-
2096
- // TODO: type-relative paths
2097
- // hir::QPath::TypeRelative(qself, segment) => {
2098
- // debug!(?qself, ?segment);
2099
- // let ty = self.lower_ty(qself);
2100
- // self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
2101
- // .map(|(ty, _, _)| ty)
2102
- // .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
2103
- // }
2104
2084
_ => ty:: Const :: new_error_with_message (
2105
2085
tcx,
2106
2086
qpath. span ( ) ,
@@ -2124,7 +2104,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2124
2104
path. segments . iter ( ) ,
2125
2105
GenericsArgsErrExtend :: Param ( def_id) ,
2126
2106
) ;
2127
- self . lower_const_arg_param ( def_id, hir_id)
2107
+ self . lower_const_param ( def_id, hir_id)
2128
2108
}
2129
2109
Res :: Def ( DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) , did) => {
2130
2110
assert_eq ! ( opt_self_ty, None ) ;
@@ -2139,37 +2119,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2139
2119
) ;
2140
2120
ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2141
2121
}
2142
- // TODO: DefKind::AssocConst?
2143
2122
_ => Const :: new_error (
2144
2123
tcx,
2145
2124
tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
2146
2125
) ,
2147
2126
}
2148
2127
}
2149
2128
2150
- /// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
2151
- /// FIXME: dedup with lower_const_param
2152
- fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
2153
- let tcx = self . tcx ( ) ;
2154
-
2155
- match tcx. named_bound_var ( path_hir_id) {
2156
- Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
2157
- // Find the name and index of the const parameter by indexing the generics of
2158
- // the parent item and construct a `ParamConst`.
2159
- let item_def_id = tcx. parent ( param_def_id) ;
2160
- let generics = tcx. generics_of ( item_def_id) ;
2161
- let index = generics. param_def_id_to_index [ & param_def_id] ;
2162
- let name = tcx. item_name ( param_def_id) ;
2163
- ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
2164
- }
2165
- Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
2166
- ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
2167
- }
2168
- Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2169
- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id) ,
2170
- }
2171
- }
2172
-
2173
2129
fn lower_delegation_ty ( & self , idx : hir:: InferDelegationKind ) -> Ty < ' tcx > {
2174
2130
let delegation_sig = self . tcx ( ) . inherit_sig_for_delegation_item ( self . item_def_id ( ) ) ;
2175
2131
match idx {
@@ -2365,7 +2321,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2365
2321
. type_of ( def_id)
2366
2322
. no_bound_vars ( )
2367
2323
. expect ( "const parameter types cannot be generic" ) ;
2368
- let ct = self . lower_const_param ( expr. hir_id ) ;
2324
+ let ct = self . lower_const_param ( def_id , expr. hir_id ) ;
2369
2325
( ct, ty)
2370
2326
}
2371
2327
0 commit comments