Skip to content

Commit f10430e

Browse files
committed
Move error handling into const_validate_mplace
1 parent e598f63 commit f10430e

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,19 +393,9 @@ fn eval_in_interpreter<'mir, 'tcx, R: InterpretationResult<'tcx>>(
393393
}
394394
Ok(mplace) => {
395395
// Since evaluation had no errors, validate the resulting constant.
396+
const_validate_mplace(&ecx, &mplace, cid)?;
396397

397-
// Temporarily allow access to the static_root_ids for the purpose of validation.
398-
let static_root_ids = ecx.machine.static_root_ids.take();
399-
let res = const_validate_mplace(&ecx, &mplace, cid);
400-
ecx.machine.static_root_ids = static_root_ids;
401-
402-
// Validation failed, report an error.
403-
if let Err(error) = res {
404-
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
405-
Err(const_report_error(&ecx, error, alloc_id))
406-
} else {
407-
Ok(R::make_result(mplace, ecx))
408-
}
398+
Ok(R::make_result(mplace, ecx))
409399
}
410400
}
411401
}
@@ -415,7 +405,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
415405
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
416406
mplace: &MPlaceTy<'tcx>,
417407
cid: GlobalId<'tcx>,
418-
) -> InterpResult<'tcx> {
408+
) -> Result<(), ErrorHandled> {
409+
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
419410
let mut ref_tracking = RefTracking::new(mplace.clone());
420411
let mut inner = false;
421412
while let Some((mplace, path)) = ref_tracking.todo.pop() {
@@ -429,7 +420,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
429420
CtfeValidationMode::Const { allow_immutable_unsafe_cell: !inner }
430421
}
431422
};
432-
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)?;
423+
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
424+
.map_err(|error| const_report_error(&ecx, error, alloc_id))?;
433425
inner = true;
434426
}
435427

0 commit comments

Comments
 (0)