@@ -293,19 +293,25 @@ pub fn eval_static_initializer_provider<'tcx>(
293
293
eval_in_interpreter ( & mut ecx, cid, true )
294
294
}
295
295
296
- pub trait InterpretationResult < ' tcx > {
296
+ pub trait InterpretationResult < ' tcx > : Sized {
297
297
fn make_result < ' mir > (
298
- mplace : MPlaceTy < ' tcx > ,
298
+ mplace : & MPlaceTy < ' tcx > ,
299
299
ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
300
- ) -> Self ;
300
+ cid : GlobalId < ' tcx > ,
301
+ ) -> InterpResult < ' tcx , Self > ;
301
302
}
302
303
303
304
impl < ' tcx > InterpretationResult < ' tcx > for ConstAlloc < ' tcx > {
304
305
fn make_result < ' mir > (
305
- mplace : MPlaceTy < ' tcx > ,
306
- _ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
307
- ) -> Self {
308
- ConstAlloc { alloc_id : mplace. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) , ty : mplace. layout . ty }
306
+ mplace : & MPlaceTy < ' tcx > ,
307
+ ecx : & mut InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
308
+ cid : GlobalId < ' tcx > ,
309
+ ) -> InterpResult < ' tcx , Self > {
310
+ const_validate_mplace ( ecx, mplace, cid) ?;
311
+ Ok ( ConstAlloc {
312
+ alloc_id : mplace. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ,
313
+ ty : mplace. layout . ty ,
314
+ } )
309
315
}
310
316
}
311
317
@@ -393,15 +399,13 @@ fn eval_in_interpreter<'mir, 'tcx, R: InterpretationResult<'tcx>>(
393
399
}
394
400
Ok ( mplace) => {
395
401
// Since evaluation had no errors, validate the resulting constant.
396
- let res = const_validate_mplace ( & ecx , & mplace , cid) ;
402
+ let res = R :: make_result ( & mplace , ecx , cid) ;
397
403
398
404
// Validation failed, report an error.
399
- if let Err ( error) = res {
405
+ res . map_err ( | error| {
400
406
let alloc_id = mplace. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ;
401
- Err ( const_report_error ( & ecx, error, alloc_id) )
402
- } else {
403
- Ok ( R :: make_result ( mplace, ecx) )
404
- }
407
+ const_report_error ( & ecx, error, alloc_id)
408
+ } )
405
409
}
406
410
}
407
411
}
0 commit comments