@@ -24,12 +24,12 @@ use crate::interpret::{
24
24
} ;
25
25
26
26
// Returns a pointer to where the result lives
27
- #[ instrument( level = "trace" , skip( ecx, body) , ret ) ]
28
- fn eval_body_using_ecx < ' mir , ' tcx > (
27
+ #[ instrument( level = "trace" , skip( ecx, body) ) ]
28
+ fn eval_body_using_ecx < ' mir , ' tcx , R : InterpretationResult < ' tcx > > (
29
29
ecx : & mut CompileTimeEvalContext < ' mir , ' tcx > ,
30
30
cid : GlobalId < ' tcx > ,
31
31
body : & ' mir mir:: Body < ' tcx > ,
32
- ) -> InterpResult < ' tcx , MPlaceTy < ' tcx > > {
32
+ ) -> InterpResult < ' tcx , R > {
33
33
trace ! ( ?ecx. param_env) ;
34
34
let tcx = * ecx. tcx ;
35
35
assert ! (
@@ -87,7 +87,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
87
87
// Since evaluation had no errors, validate the resulting constant.
88
88
const_validate_mplace ( & ecx, & ret, cid) ?;
89
89
90
- Ok ( ret)
90
+ Ok ( R :: make_result ( ret, ecx ) )
91
91
}
92
92
93
93
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
@@ -291,14 +291,14 @@ pub fn eval_static_initializer_provider<'tcx>(
291
291
pub trait InterpretationResult < ' tcx > {
292
292
fn make_result < ' mir > (
293
293
mplace : MPlaceTy < ' tcx > ,
294
- ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
294
+ ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
295
295
) -> Self ;
296
296
}
297
297
298
298
impl < ' tcx > InterpretationResult < ' tcx > for ConstAlloc < ' tcx > {
299
299
fn make_result < ' mir > (
300
300
mplace : MPlaceTy < ' tcx > ,
301
- _ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
301
+ _ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
302
302
) -> Self {
303
303
ConstAlloc { alloc_id : mplace. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) , ty : mplace. layout . ty }
304
304
}
@@ -349,41 +349,33 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
349
349
CompileTimeInterpreter :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
350
350
) ;
351
351
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
352
- match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) {
353
- Err ( error) => {
354
- let ( error, backtrace) = error. into_parts ( ) ;
355
- backtrace. print_backtrace ( ) ;
356
-
357
- let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
358
- ( "static" , String :: new ( ) )
352
+ res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) . map_err ( |error| {
353
+ let ( error, backtrace) = error. into_parts ( ) ;
354
+ backtrace. print_backtrace ( ) ;
355
+
356
+ let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
357
+ ( "static" , String :: new ( ) )
358
+ } else {
359
+ // If the current item has generics, we'd like to enrich the message with the
360
+ // instance and its args: to show the actual compile-time values, in addition to
361
+ // the expression, leading to the const eval error.
362
+ let instance = & cid. instance ;
363
+ if !instance. args . is_empty ( ) {
364
+ let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
365
+ ( "const_with_path" , instance)
359
366
} else {
360
- // If the current item has generics, we'd like to enrich the message with the
361
- // instance and its args: to show the actual compile-time values, in addition to
362
- // the expression, leading to the const eval error.
363
- let instance = & cid. instance ;
364
- if !instance. args . is_empty ( ) {
365
- let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
366
- ( "const_with_path" , instance)
367
- } else {
368
- ( "const" , String :: new ( ) )
369
- }
370
- } ;
371
-
372
- Err ( super :: report (
373
- * ecx. tcx ,
374
- error,
375
- None ,
376
- || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
377
- |span, frames| ConstEvalError {
378
- span,
379
- error_kind : kind,
380
- instance,
381
- frame_notes : frames,
382
- } ,
383
- ) )
384
- }
385
- Ok ( mplace) => Ok ( R :: make_result ( mplace, ecx) ) ,
386
- }
367
+ ( "const" , String :: new ( ) )
368
+ }
369
+ } ;
370
+
371
+ super :: report (
372
+ * ecx. tcx ,
373
+ error,
374
+ None ,
375
+ || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
376
+ |span, frames| ConstEvalError { span, error_kind : kind, instance, frame_notes : frames } ,
377
+ )
378
+ } )
387
379
}
388
380
389
381
#[ inline( always) ]
0 commit comments