@@ -386,33 +386,8 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
386386        CompileTimeMachine :: new ( CanAccessMutGlobal :: from ( is_static) ,  CheckAlignment :: Error ) , 
387387    ) ; 
388388    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) ) 
416391} 
417392
418393#[ inline( always) ]  
@@ -438,24 +413,61 @@ fn const_validate_mplace<'tcx>(
438413        ecx. const_validate_operand ( & mplace. into ( ) ,  path,  & mut  ref_tracking,  mode) 
439414            // Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted 
440415            // 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) ) ?; 
442417        inner = true ; 
443418    } 
444419
445420    Ok ( ( ) ) 
446421} 
447422
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) ]  
449457fn  report_validation_error < ' tcx > ( 
450458    ecx :  & InterpCx < ' tcx ,  CompileTimeMachine < ' tcx > > , 
459+     cid :  GlobalId < ' tcx > , 
451460    error :  InterpErrorInfo < ' tcx > , 
452461    alloc_id :  AllocId , 
453462)  -> 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+ 
454468    let  ( error,  backtrace)  = error. into_parts ( ) ; 
455469    backtrace. print_backtrace ( ) ; 
456470
457-     let  ub_note = matches ! ( error,  InterpError :: UndefinedBehavior ( _) ) . then ( || { } ) ; 
458- 
459471    let  bytes = ecx. print_alloc_bytes_for_diagnostics ( alloc_id) ; 
460472    let  ( size,  align,  _)  = ecx. get_alloc_info ( alloc_id) ; 
461473    let  raw_bytes = errors:: RawBytesNote  {  size :  size. bytes ( ) ,  align :  align. bytes ( ) ,  bytes } ; 
@@ -465,6 +477,6 @@ fn report_validation_error<'tcx>(
465477        error, 
466478        DUMMY_SP , 
467479        || 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 } , 
469481    ) 
470482} 
0 commit comments