This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed
compiler/rustc_const_eval/src/const_eval Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
110
110
pub ( super ) fn op_to_const < ' tcx > (
111
111
ecx : & CompileTimeEvalContext < ' _ , ' tcx > ,
112
112
op : & OpTy < ' tcx > ,
113
+ for_diagnostics : bool ,
113
114
) -> ConstValue < ' tcx > {
114
115
// Handle ZST consistently and early.
115
116
if op. layout . is_zst ( ) {
@@ -132,8 +133,14 @@ pub(super) fn op_to_const<'tcx>(
132
133
// functionality.)
133
134
_ => false ,
134
135
} ;
135
- let immediate = if force_as_immediate && let Ok ( imm) = ecx. read_immediate ( op) {
136
- Right ( imm)
136
+ let immediate = if force_as_immediate {
137
+ match ecx. read_immediate ( op) {
138
+ Ok ( imm) => Right ( imm) ,
139
+ Err ( err) if !for_diagnostics => {
140
+ panic ! ( "normalization works on validated constants: {err:?}" )
141
+ }
142
+ _ => op. as_mplace_or_imm ( ) ,
143
+ }
137
144
} else {
138
145
op. as_mplace_or_imm ( )
139
146
} ;
@@ -205,7 +212,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
205
212
) ;
206
213
207
214
// Turn this into a proper constant.
208
- op_to_const ( & ecx, & mplace. into ( ) )
215
+ op_to_const ( & ecx, & mplace. into ( ) , /* for diagnostics */ false )
209
216
}
210
217
211
218
#[ instrument( skip( tcx) , level = "debug" ) ]
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
99
99
let fields_iter = ( 0 ..field_count)
100
100
. map ( |i| {
101
101
let field_op = ecx. project_field ( & down, i) . ok ( ) ?;
102
- let val = op_to_const ( & ecx, & field_op) ;
102
+ let val = op_to_const ( & ecx, & field_op, /* for diagnostics */ true ) ;
103
103
Some ( ( val, field_op. layout . ty ) )
104
104
} )
105
105
. collect :: < Option < Vec < _ > > > ( ) ?;
Original file line number Diff line number Diff line change @@ -232,7 +232,7 @@ pub fn valtree_to_const_value<'tcx>(
232
232
let mut ecx = mk_eval_cx ( tcx, DUMMY_SP , param_env, CanAccessStatics :: No ) ;
233
233
let imm = valtree_to_ref ( & mut ecx, valtree, * inner_ty) ;
234
234
let imm = ImmTy :: from_immediate ( imm, tcx. layout_of ( param_env_ty) . unwrap ( ) ) ;
235
- op_to_const ( & ecx, & imm. into ( ) )
235
+ op_to_const ( & ecx, & imm. into ( ) , /* for diagnostics */ false )
236
236
}
237
237
ty:: Tuple ( _) | ty:: Array ( _, _) | ty:: Adt ( ..) => {
238
238
let layout = tcx. layout_of ( param_env_ty) . unwrap ( ) ;
@@ -265,7 +265,7 @@ pub fn valtree_to_const_value<'tcx>(
265
265
dump_place ( & ecx, & place) ;
266
266
intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & place) . unwrap ( ) ;
267
267
268
- op_to_const ( & ecx, & place. into ( ) )
268
+ op_to_const ( & ecx, & place. into ( ) , /* for diagnostics */ false )
269
269
}
270
270
ty:: Never
271
271
| ty:: Error ( _)
You can’t perform that action at this time.
0 commit comments