Skip to content

Commit

Permalink
Rename some things around validation error reporting to signal that i…
Browse files Browse the repository at this point in the history
…t is in fact about validation failures
  • Loading branch information
oli-obk committed Mar 13, 2024
1 parent 2a1a6fa commit a3fa705
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
}

#[inline(always)]
pub fn const_validate_mplace<'mir, 'tcx>(
fn const_validate_mplace<'mir, 'tcx>(
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
mplace: &MPlaceTy<'tcx>,
cid: GlobalId<'tcx>,
Expand All @@ -402,15 +402,17 @@ pub fn const_validate_mplace<'mir, 'tcx>(
}
};
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
.map_err(|error| const_report_error(&ecx, error, alloc_id))?;
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targetted
// error about the validation failure.
.map_err(|error| report_validation_error(&ecx, error, alloc_id))?;
inner = true;
}

Ok(())
}

#[inline(always)]
pub fn const_report_error<'mir, 'tcx>(
fn report_validation_error<'mir, 'tcx>(
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
error: InterpErrorInfo<'tcx>,
alloc_id: AllocId,
Expand All @@ -429,6 +431,6 @@ pub fn const_report_error<'mir, 'tcx>(
error,
None,
|| crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()),
move |span, frames| errors::UndefinedBehavior { span, ub_note, frames, raw_bytes },
move |span, frames| errors::ValidationFailure { span, ub_note, frames, raw_bytes },
)
}
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub struct NullaryIntrinsicError {

#[derive(Diagnostic)]
#[diag(const_eval_undefined_behavior, code = E0080)]
pub struct UndefinedBehavior {
pub struct ValidationFailure {
#[primary_span]
pub span: Span,
#[note(const_eval_undefined_behavior_note)]
Expand Down

0 comments on commit a3fa705

Please sign in to comment.