Skip to content

Commit 31fa142

Browse files
committed
Move error handling into const_validate_mplace
1 parent 44b1f8a commit 31fa142

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,9 @@ fn eval_in_interpreter<'mir, 'tcx, R: InterpretationResult<'tcx>>(
396396
}
397397
Ok(mplace) => {
398398
// Since evaluation had no errors, validate the resulting constant.
399+
const_validate_mplace(&ecx, &mplace, cid)?;
399400

400-
let res = const_validate_mplace(&ecx, &mplace, cid);
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-
}
401+
Ok(R::make_result(mplace, ecx))
409402
}
410403
}
411404
}
@@ -415,7 +408,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
415408
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
416409
mplace: &MPlaceTy<'tcx>,
417410
cid: GlobalId<'tcx>,
418-
) -> InterpResult<'tcx> {
411+
) -> Result<(), ErrorHandled> {
412+
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
419413
let mut ref_tracking = RefTracking::new(mplace.clone());
420414
let mut inner = false;
421415
while let Some((mplace, path)) = ref_tracking.todo.pop() {
@@ -429,7 +423,8 @@ pub fn const_validate_mplace<'mir, 'tcx>(
429423
CtfeValidationMode::Const { allow_immutable_unsafe_cell: !inner }
430424
}
431425
};
432-
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)?;
426+
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
427+
.map_err(|error| const_report_error(&ecx, error, alloc_id))?;
433428
inner = true;
434429
}
435430

0 commit comments

Comments
 (0)