@@ -20,7 +20,7 @@ use crate::const_eval::CheckAlignment;
2020use crate :: interpret:: {
2121 CtfeValidationMode , GlobalId , Immediate , InternKind , InternResult , InterpCx , InterpError ,
2222 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,
2424} ;
2525use crate :: { CTRL_C_RECEIVED , errors} ;
2626
@@ -98,19 +98,19 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
9898 return Err ( ecx
9999 . tcx
100100 . 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 ( ) ;
103103 }
104104 Err ( InternResult :: FoundBadMutablePointer ) => {
105105 return Err ( ecx
106106 . tcx
107107 . 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 ( ) ;
110110 }
111111 }
112112
113- Ok ( R :: make_result ( ret, ecx) )
113+ interp_ok ( R :: make_result ( ret, ecx) )
114114}
115115
116116/// 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>(
147147 ty : Ty < ' tcx > ,
148148) -> Option < ( CompileTimeInterpCx < ' tcx > , OpTy < ' tcx > ) > {
149149 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 ( ) ?;
151152 Some ( ( ecx, op) )
152153}
153154
@@ -185,12 +186,16 @@ pub(super) fn op_to_const<'tcx>(
185186 _ => false ,
186187 } ;
187188 let immediate = if force_as_immediate {
188- match ecx. read_immediate ( op) {
189+ match ecx. read_immediate ( op) . report_err ( ) {
189190 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+ }
192198 }
193- _ => op. as_mplace_or_imm ( ) ,
194199 }
195200 } else {
196201 op. as_mplace_or_imm ( )
@@ -283,17 +288,19 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
283288 let ty:: FnDef ( _, args) = ty. kind ( ) else {
284289 bug ! ( "intrinsic with type {:?}" , ty) ;
285290 } ;
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+ ) ;
297304 }
298305
299306 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>>(
376383 ) ;
377384 let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
378385 res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) )
386+ . report_err ( )
379387 . map_err ( |error| report_eval_error ( & ecx, cid, error) )
380388}
381389
@@ -400,6 +408,7 @@ fn const_validate_mplace<'tcx>(
400408 }
401409 } ;
402410 ecx. const_validate_operand ( & mplace. into ( ) , path, & mut ref_tracking, mode)
411+ . report_err ( )
403412 // Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted
404413 // error about the validation failure.
405414 . map_err ( |error| report_validation_error ( & ecx, cid, error, alloc_id) ) ?;
0 commit comments