@@ -135,6 +135,9 @@ impl<'tcx> Const<'tcx> {
135
135
_,
136
136
& hir:: Path { res : Res :: Def ( DefKind :: ConstParam , def_id) , .. } ,
137
137
) ) => {
138
+ // Use the type from the param's definition, since we can resolve it,
139
+ // not the expected parameter type from WithOptConstParam.
140
+ let param_ty = tcx. type_of ( def_id) . subst_identity ( ) ;
138
141
match tcx. named_bound_var ( expr. hir_id ) {
139
142
Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
140
143
// Find the name and index of the const parameter by indexing the generics of
@@ -143,14 +146,14 @@ impl<'tcx> Const<'tcx> {
143
146
let generics = tcx. generics_of ( item_def_id) ;
144
147
let index = generics. param_def_id_to_index [ & def_id] ;
145
148
let name = tcx. item_name ( def_id) ;
146
- Some ( tcx. mk_const ( ty:: ParamConst :: new ( index, name) , ty ) )
149
+ Some ( tcx. mk_const ( ty:: ParamConst :: new ( index, name) , param_ty ) )
147
150
}
148
151
Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => Some ( tcx. mk_const (
149
152
ty:: ConstKind :: Bound ( debruijn, ty:: BoundVar :: from_u32 ( index) ) ,
150
- ty ,
153
+ param_ty ,
151
154
) ) ,
152
155
Some ( rbv:: ResolvedArg :: Error ( guar) ) => {
153
- Some ( tcx. const_error_with_guaranteed ( ty , guar) )
156
+ Some ( tcx. const_error_with_guaranteed ( param_ty , guar) )
154
157
}
155
158
arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , expr. hir_id) ,
156
159
}
0 commit comments