@@ -386,33 +386,8 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
386
386
CompileTimeMachine :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
387
387
) ;
388
388
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
389
- res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) . map_err ( |error| {
390
- let ( error, backtrace) = error. into_parts ( ) ;
391
- backtrace. print_backtrace ( ) ;
392
-
393
- let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
394
- ( "static" , String :: new ( ) )
395
- } else {
396
- // If the current item has generics, we'd like to enrich the message with the
397
- // instance and its args: to show the actual compile-time values, in addition to
398
- // the expression, leading to the const eval error.
399
- let instance = & cid. instance ;
400
- if !instance. args . is_empty ( ) {
401
- let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
402
- ( "const_with_path" , instance)
403
- } else {
404
- ( "const" , String :: new ( ) )
405
- }
406
- } ;
407
-
408
- super :: report (
409
- * ecx. tcx ,
410
- error,
411
- DUMMY_SP ,
412
- || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
413
- |span, frames| ConstEvalError { span, error_kind : kind, instance, frame_notes : frames } ,
414
- )
415
- } )
389
+ res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) )
390
+ . map_err ( |error| report_eval_error ( & ecx, cid, error) )
416
391
}
417
392
418
393
#[ inline( always) ]
@@ -438,24 +413,61 @@ fn const_validate_mplace<'tcx>(
438
413
ecx. const_validate_operand ( & mplace. into ( ) , path, & mut ref_tracking, mode)
439
414
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted
440
415
// error about the validation failure.
441
- . map_err ( |error| report_validation_error ( & ecx, error, alloc_id) ) ?;
416
+ . map_err ( |error| report_validation_error ( & ecx, cid , error, alloc_id) ) ?;
442
417
inner = true ;
443
418
}
444
419
445
420
Ok ( ( ) )
446
421
}
447
422
448
- #[ inline( always) ]
423
+ #[ inline( never) ]
424
+ fn report_eval_error < ' tcx > (
425
+ ecx : & InterpCx < ' tcx , CompileTimeMachine < ' tcx > > ,
426
+ cid : GlobalId < ' tcx > ,
427
+ error : InterpErrorInfo < ' tcx > ,
428
+ ) -> ErrorHandled {
429
+ let ( error, backtrace) = error. into_parts ( ) ;
430
+ backtrace. print_backtrace ( ) ;
431
+
432
+ let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
433
+ ( "static" , String :: new ( ) )
434
+ } else {
435
+ // If the current item has generics, we'd like to enrich the message with the
436
+ // instance and its args: to show the actual compile-time values, in addition to
437
+ // the expression, leading to the const eval error.
438
+ let instance = & cid. instance ;
439
+ if !instance. args . is_empty ( ) {
440
+ let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
441
+ ( "const_with_path" , instance)
442
+ } else {
443
+ ( "const" , String :: new ( ) )
444
+ }
445
+ } ;
446
+
447
+ super :: report (
448
+ * ecx. tcx ,
449
+ error,
450
+ DUMMY_SP ,
451
+ || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
452
+ |span, frames| ConstEvalError { span, error_kind : kind, instance, frame_notes : frames } ,
453
+ )
454
+ }
455
+
456
+ #[ inline( never) ]
449
457
fn report_validation_error < ' tcx > (
450
458
ecx : & InterpCx < ' tcx , CompileTimeMachine < ' tcx > > ,
459
+ cid : GlobalId < ' tcx > ,
451
460
error : InterpErrorInfo < ' tcx > ,
452
461
alloc_id : AllocId ,
453
462
) -> ErrorHandled {
463
+ if !matches ! ( error. kind( ) , InterpError :: UndefinedBehavior ( _) ) {
464
+ // Some other error happened during validation, e.g. an unsupported operation.
465
+ return report_eval_error ( ecx, cid, error) ;
466
+ }
467
+
454
468
let ( error, backtrace) = error. into_parts ( ) ;
455
469
backtrace. print_backtrace ( ) ;
456
470
457
- let ub_note = matches ! ( error, InterpError :: UndefinedBehavior ( _) ) . then ( || { } ) ;
458
-
459
471
let bytes = ecx. print_alloc_bytes_for_diagnostics ( alloc_id) ;
460
472
let ( size, align, _) = ecx. get_alloc_info ( alloc_id) ;
461
473
let raw_bytes = errors:: RawBytesNote { size : size. bytes ( ) , align : align. bytes ( ) , bytes } ;
@@ -465,6 +477,6 @@ fn report_validation_error<'tcx>(
465
477
error,
466
478
DUMMY_SP ,
467
479
|| crate :: const_eval:: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
468
- move |span, frames| errors:: ValidationFailure { span, ub_note, frames, raw_bytes } ,
480
+ move |span, frames| errors:: ValidationFailure { span, ub_note : ( ) , frames, raw_bytes } ,
469
481
)
470
482
}
0 commit comments