@@ -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
@@ -294,14 +294,14 @@ pub trait InterpretationResult<'tcx> {
294
294
/// evaluation query.
295
295
fn make_result < ' mir > (
296
296
mplace : MPlaceTy < ' tcx > ,
297
- ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
297
+ ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
298
298
) -> Self ;
299
299
}
300
300
301
301
impl < ' tcx > InterpretationResult < ' tcx > for ConstAlloc < ' tcx > {
302
302
fn make_result < ' mir > (
303
303
mplace : MPlaceTy < ' tcx > ,
304
- _ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
304
+ _ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
305
305
) -> Self {
306
306
ConstAlloc { alloc_id : mplace. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) , ty : mplace. layout . ty }
307
307
}
@@ -352,41 +352,33 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
352
352
CompileTimeInterpreter :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
353
353
) ;
354
354
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
355
- match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) {
356
- Err ( error) => {
357
- let ( error, backtrace) = error. into_parts ( ) ;
358
- backtrace. print_backtrace ( ) ;
359
-
360
- let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
361
- ( "static" , String :: new ( ) )
355
+ res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) . map_err ( |error| {
356
+ let ( error, backtrace) = error. into_parts ( ) ;
357
+ backtrace. print_backtrace ( ) ;
358
+
359
+ let ( kind, instance) = if ecx. tcx . is_static ( cid. instance . def_id ( ) ) {
360
+ ( "static" , String :: new ( ) )
361
+ } else {
362
+ // If the current item has generics, we'd like to enrich the message with the
363
+ // instance and its args: to show the actual compile-time values, in addition to
364
+ // the expression, leading to the const eval error.
365
+ let instance = & cid. instance ;
366
+ if !instance. args . is_empty ( ) {
367
+ let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
368
+ ( "const_with_path" , instance)
362
369
} else {
363
- // If the current item has generics, we'd like to enrich the message with the
364
- // instance and its args: to show the actual compile-time values, in addition to
365
- // the expression, leading to the const eval error.
366
- let instance = & cid. instance ;
367
- if !instance. args . is_empty ( ) {
368
- let instance = with_no_trimmed_paths ! ( instance. to_string( ) ) ;
369
- ( "const_with_path" , instance)
370
- } else {
371
- ( "const" , String :: new ( ) )
372
- }
373
- } ;
374
-
375
- Err ( super :: report (
376
- * ecx. tcx ,
377
- error,
378
- None ,
379
- || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
380
- |span, frames| ConstEvalError {
381
- span,
382
- error_kind : kind,
383
- instance,
384
- frame_notes : frames,
385
- } ,
386
- ) )
387
- }
388
- Ok ( mplace) => Ok ( R :: make_result ( mplace, ecx) ) ,
389
- }
370
+ ( "const" , String :: new ( ) )
371
+ }
372
+ } ;
373
+
374
+ super :: report (
375
+ * ecx. tcx ,
376
+ error,
377
+ None ,
378
+ || super :: get_span_and_frames ( ecx. tcx , ecx. stack ( ) ) ,
379
+ |span, frames| ConstEvalError { span, error_kind : kind, instance, frame_notes : frames } ,
380
+ )
381
+ } )
390
382
}
391
383
392
384
#[ inline( always) ]
0 commit comments