@@ -20,7 +20,7 @@ use crate::const_eval::CheckAlignment;
20
20
use crate :: interpret:: {
21
21
CtfeValidationMode , GlobalId , Immediate , InternKind , InternResult , InterpCx , InterpError ,
22
22
InterpResult , MPlaceTy , MemoryKind , OpTy , RefTracking , StackPopCleanup , create_static_alloc,
23
- eval_nullary_intrinsic, intern_const_alloc_recursive, throw_exhaust,
23
+ eval_nullary_intrinsic, intern_const_alloc_recursive, interp_ok , throw_exhaust,
24
24
} ;
25
25
use crate :: { CTRL_C_RECEIVED , errors} ;
26
26
@@ -98,19 +98,19 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
98
98
return Err ( ecx
99
99
. tcx
100
100
. dcx ( )
101
- . emit_err ( errors:: DanglingPtrInFinal { span : ecx. tcx . span , kind : intern_kind } )
102
- . into ( ) ) ;
101
+ . emit_err ( errors:: DanglingPtrInFinal { span : ecx. tcx . span , kind : intern_kind } ) )
102
+ . into ( ) ;
103
103
}
104
104
Err ( InternResult :: FoundBadMutablePointer ) => {
105
105
return Err ( ecx
106
106
. tcx
107
107
. dcx ( )
108
- . emit_err ( errors:: MutablePtrInFinal { span : ecx. tcx . span , kind : intern_kind } )
109
- . into ( ) ) ;
108
+ . emit_err ( errors:: MutablePtrInFinal { span : ecx. tcx . span , kind : intern_kind } ) )
109
+ . into ( ) ;
110
110
}
111
111
}
112
112
113
- Ok ( R :: make_result ( ret, ecx) )
113
+ interp_ok ( R :: make_result ( ret, ecx) )
114
114
}
115
115
116
116
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
@@ -147,7 +147,8 @@ pub fn mk_eval_cx_for_const_val<'tcx>(
147
147
ty : Ty < ' tcx > ,
148
148
) -> Option < ( CompileTimeInterpCx < ' tcx > , OpTy < ' tcx > ) > {
149
149
let ecx = mk_eval_cx_to_read_const_val ( tcx. tcx , tcx. span , param_env, CanAccessMutGlobal :: No ) ;
150
- let op = ecx. const_val_to_op ( val, ty, None ) . ok ( ) ?;
150
+ // FIXME: is it a problem to discard the error here?
151
+ let op = ecx. const_val_to_op ( val, ty, None ) . discard_err ( ) ?;
151
152
Some ( ( ecx, op) )
152
153
}
153
154
@@ -185,12 +186,16 @@ pub(super) fn op_to_const<'tcx>(
185
186
_ => false ,
186
187
} ;
187
188
let immediate = if force_as_immediate {
188
- match ecx. read_immediate ( op) {
189
+ match ecx. read_immediate ( op) . report_err ( ) {
189
190
Ok ( imm) => Right ( imm) ,
190
- Err ( err) if !for_diagnostics => {
191
- panic ! ( "normalization works on validated constants: {err:?}" )
191
+ Err ( err) => {
192
+ if for_diagnostics {
193
+ // This discard the error, but for diagnostics that's okay.
194
+ op. as_mplace_or_imm ( )
195
+ } else {
196
+ panic ! ( "normalization works on validated constants: {err:?}" )
197
+ }
192
198
}
193
- _ => op. as_mplace_or_imm ( ) ,
194
199
}
195
200
} else {
196
201
op. as_mplace_or_imm ( )
@@ -283,17 +288,19 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
283
288
let ty:: FnDef ( _, args) = ty. kind ( ) else {
284
289
bug ! ( "intrinsic with type {:?}" , ty) ;
285
290
} ;
286
- return eval_nullary_intrinsic ( tcx, key. param_env , def_id, args) . map_err ( |error| {
287
- let span = tcx. def_span ( def_id) ;
288
-
289
- super :: report (
290
- tcx,
291
- error. into_kind ( ) ,
292
- span,
293
- || ( span, vec ! [ ] ) ,
294
- |span, _| errors:: NullaryIntrinsicError { span } ,
295
- )
296
- } ) ;
291
+ return eval_nullary_intrinsic ( tcx, key. param_env , def_id, args) . report_err ( ) . map_err (
292
+ |error| {
293
+ let span = tcx. def_span ( def_id) ;
294
+
295
+ super :: report (
296
+ tcx,
297
+ error. into_kind ( ) ,
298
+ span,
299
+ || ( span, vec ! [ ] ) ,
300
+ |span, _| errors:: NullaryIntrinsicError { span } ,
301
+ )
302
+ } ,
303
+ ) ;
297
304
}
298
305
299
306
tcx. eval_to_allocation_raw ( key) . map ( |val| turn_into_const_value ( tcx, val, key) )
@@ -376,6 +383,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
376
383
) ;
377
384
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
378
385
res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) )
386
+ . report_err ( )
379
387
. map_err ( |error| report_eval_error ( & ecx, cid, error) )
380
388
}
381
389
@@ -400,6 +408,7 @@ fn const_validate_mplace<'tcx>(
400
408
}
401
409
} ;
402
410
ecx. const_validate_operand ( & mplace. into ( ) , path, & mut ref_tracking, mode)
411
+ . report_err ( )
403
412
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted
404
413
// error about the validation failure.
405
414
. map_err ( |error| report_validation_error ( & ecx, cid, error, alloc_id) ) ?;
0 commit comments