@@ -2040,23 +2040,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2040
2040
///
2041
2041
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
2042
2042
/// and late-bound ones to [`ty::ConstKind::Bound`].
2043
- pub ( crate ) fn lower_const_param ( & self , hir_id : HirId ) -> Const < ' tcx > {
2043
+ pub ( crate ) fn lower_const_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
2044
2044
let tcx = self . tcx ( ) ;
2045
- match tcx. named_bound_var ( hir_id) {
2046
- Some ( rbv:: ResolvedArg :: EarlyBound ( def_id) ) => {
2045
+
2046
+ match tcx. named_bound_var ( path_hir_id) {
2047
+ Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
2047
2048
// Find the name and index of the const parameter by indexing the generics of
2048
2049
// the parent item and construct a `ParamConst`.
2049
- let item_def_id = tcx. local_parent ( def_id ) ;
2050
+ let item_def_id = tcx. parent ( param_def_id ) ;
2050
2051
let generics = tcx. generics_of ( item_def_id) ;
2051
- let index = generics. param_def_id_to_index [ & def_id . to_def_id ( ) ] ;
2052
- let name = tcx. item_name ( def_id . to_def_id ( ) ) ;
2052
+ let index = generics. param_def_id_to_index [ & param_def_id ] ;
2053
+ let name = tcx. item_name ( param_def_id ) ;
2053
2054
ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
2054
2055
}
2055
2056
Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
2056
2057
ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
2057
2058
}
2058
2059
Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2059
- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , hir_id ) ,
2060
+ arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id ) ,
2060
2061
}
2061
2062
}
2062
2063
@@ -2085,10 +2086,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2085
2086
fn lower_const_arg_path ( & self , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Const < ' tcx > {
2086
2087
let tcx = self . tcx ( ) ;
2087
2088
2088
- // TODO: handle path args properly
2089
2089
match qpath {
2090
2090
hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , did) , .. } ) => {
2091
- self . lower_const_arg_param ( did, hir_id)
2091
+ self . lower_const_param ( did, hir_id)
2092
2092
}
2093
2093
hir:: QPath :: Resolved (
2094
2094
_,
@@ -2098,31 +2098,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2098
2098
qpath. span ( ) ,
2099
2099
"fn's cannot be used as const args" ,
2100
2100
) ,
2101
- // hir::QPath::Resolved(_, path @ &hir::Path { res: Res::Def(_, did), .. }) => {
2102
- // let (item_segment, _) = path.segments.split_last().unwrap();
2103
- // let args = self.lower_generic_args_of_path_segment(path.span, did, item_segment);
2104
- // ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
2105
- // }
2106
- // // TODO: type-relative paths
2107
- // _ => ty::Const::new_error_with_message(
2108
- // tcx,
2109
- // qpath.span(),
2110
- // "Const::lower_const_arg_path: invalid qpath",
2111
- // ),
2112
2101
hir:: QPath :: Resolved ( maybe_qself, path) => {
2113
2102
debug ! ( ?maybe_qself, ?path) ;
2114
2103
let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2115
2104
self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
2116
2105
}
2117
-
2118
- // TODO: type-relative paths
2119
- // hir::QPath::TypeRelative(qself, segment) => {
2120
- // debug!(?qself, ?segment);
2121
- // let ty = self.lower_ty(qself);
2122
- // self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
2123
- // .map(|(ty, _, _)| ty)
2124
- // .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
2125
- // }
2126
2106
_ => ty:: Const :: new_error_with_message (
2127
2107
tcx,
2128
2108
qpath. span ( ) ,
@@ -2146,7 +2126,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2146
2126
path. segments . iter ( ) ,
2147
2127
GenericsArgsErrExtend :: Param ( def_id) ,
2148
2128
) ;
2149
- self . lower_const_arg_param ( def_id, hir_id)
2129
+ self . lower_const_param ( def_id, hir_id)
2150
2130
}
2151
2131
Res :: Def ( DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) , did) => {
2152
2132
assert_eq ! ( opt_self_ty, None ) ;
@@ -2161,37 +2141,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2161
2141
) ;
2162
2142
ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2163
2143
}
2164
- // TODO: DefKind::AssocConst?
2165
2144
_ => Const :: new_error (
2166
2145
tcx,
2167
2146
tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
2168
2147
) ,
2169
2148
}
2170
2149
}
2171
2150
2172
- /// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
2173
- /// FIXME: dedup with lower_const_param
2174
- fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
2175
- let tcx = self . tcx ( ) ;
2176
-
2177
- match tcx. named_bound_var ( path_hir_id) {
2178
- Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
2179
- // Find the name and index of the const parameter by indexing the generics of
2180
- // the parent item and construct a `ParamConst`.
2181
- let item_def_id = tcx. parent ( param_def_id) ;
2182
- let generics = tcx. generics_of ( item_def_id) ;
2183
- let index = generics. param_def_id_to_index [ & param_def_id] ;
2184
- let name = tcx. item_name ( param_def_id) ;
2185
- ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
2186
- }
2187
- Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
2188
- ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
2189
- }
2190
- Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2191
- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id) ,
2192
- }
2193
- }
2194
-
2195
2151
fn lower_delegation_ty ( & self , idx : hir:: InferDelegationKind ) -> Ty < ' tcx > {
2196
2152
let delegation_sig = self . tcx ( ) . inherit_sig_for_delegation_item ( self . item_def_id ( ) ) ;
2197
2153
match idx {
@@ -2387,7 +2343,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2387
2343
. type_of ( def_id)
2388
2344
. no_bound_vars ( )
2389
2345
. expect ( "const parameter types cannot be generic" ) ;
2390
- let ct = self . lower_const_param ( expr. hir_id ) ;
2346
+ let ct = self . lower_const_param ( def_id , expr. hir_id ) ;
2391
2347
( ct, ty)
2392
2348
}
2393
2349
0 commit comments