Skip to content

Commit 76440f3

Browse files
committed
Move error handling into const_validate_mplace
1 parent db45044 commit 76440f3

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ pub trait InterpretationResult<'tcx>: Sized {
298298
mplace: &MPlaceTy<'tcx>,
299299
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
300300
cid: GlobalId<'tcx>,
301-
) -> InterpResult<'tcx, Self>;
301+
) -> Result<Self, ErrorHandled>;
302302
}
303303

304304
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
305305
fn make_result<'mir>(
306306
mplace: &MPlaceTy<'tcx>,
307307
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
308308
cid: GlobalId<'tcx>,
309-
) -> InterpResult<'tcx, Self> {
309+
) -> Result<Self, ErrorHandled> {
310310
const_validate_mplace(ecx, mplace, cid)?;
311311
Ok(ConstAlloc {
312312
alloc_id: mplace.ptr().provenance.unwrap().alloc_id(),
@@ -399,13 +399,7 @@ fn eval_in_interpreter<'mir, 'tcx, R: InterpretationResult<'tcx>>(
399399
}
400400
Ok(mplace) => {
401401
// Since evaluation had no errors, validate the resulting constant.
402-
let res = R::make_result(&mplace, ecx, cid);
403-
404-
// Validation failed, report an error.
405-
res.map_err(|error| {
406-
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
407-
const_report_error(&ecx, error, alloc_id)
408-
})
402+
R::make_result(&mplace, ecx, cid)
409403
}
410404
}
411405
}
@@ -415,7 +409,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
415409
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
416410
mplace: &MPlaceTy<'tcx>,
417411
cid: GlobalId<'tcx>,
418-
) -> InterpResult<'tcx> {
412+
) -> Result<(), ErrorHandled> {
413+
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
419414
let mut ref_tracking = RefTracking::new(mplace.clone());
420415
let mut inner = false;
421416
while let Some((mplace, path)) = ref_tracking.todo.pop() {
@@ -429,7 +424,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
429424
CtfeValidationMode::Const { allow_immutable_unsafe_cell }
430425
}
431426
};
432-
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)?;
427+
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
428+
.map_err(|error| const_report_error(&ecx, error, alloc_id))?;
433429
inner = true;
434430
}
435431

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::const_eval::{CompileTimeEvalContext, CompileTimeInterpreter, InterpretationResult};
22
use crate::interpret::{MemPlaceMeta, MemoryKind};
33
use rustc_middle::mir;
4-
use rustc_middle::mir::interpret::{Allocation, GlobalId, InterpResult, Pointer};
4+
use rustc_middle::mir::interpret::{Allocation, ErrorHandled, GlobalId, InterpResult, Pointer};
55
use rustc_middle::ty::layout::TyAndLayout;
66
use rustc_middle::ty::{
77
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
@@ -86,7 +86,7 @@ impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx>
8686
mplace: &MPlaceTy<'tcx>,
8787
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
8888
cid: GlobalId<'tcx>,
89-
) -> InterpResult<'tcx, Self> {
89+
) -> Result<Self, ErrorHandled> {
9090
crate::const_eval::const_validate_mplace(ecx, mplace, cid)?;
9191
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
9292
let alloc = ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1;

0 commit comments

Comments
 (0)