Skip to content

Commit a316c21

Browse files
committed
Rename some things around validation error reporting to signal that it is in fact about validation failures
1 parent 16046c7 commit a316c21

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

compiler/rustc_const_eval/messages.ftl

+6-6
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,6 @@ const_eval_unallowed_op_in_const_context =
374374
const_eval_unavailable_target_features_for_fn =
375375
calling a function that requires unavailable target features: {$unavailable_feats}
376376
377-
const_eval_undefined_behavior =
378-
it is undefined behavior to use this value
379-
380-
const_eval_undefined_behavior_note =
381-
The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
382-
383377
const_eval_uninhabited_enum_variant_read =
384378
read discriminant of an uninhabited enum variant
385379
const_eval_uninhabited_enum_variant_written =
@@ -434,6 +428,12 @@ const_eval_validation_expected_raw_ptr = expected a raw pointer
434428
const_eval_validation_expected_ref = expected a reference
435429
const_eval_validation_expected_str = expected a string
436430
431+
const_eval_validation_failure =
432+
it is undefined behavior to use this value
433+
434+
const_eval_validation_failure_note =
435+
The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
436+
437437
const_eval_validation_front_matter_invalid_value = constructing invalid value
438438
const_eval_validation_front_matter_invalid_value_with_path = constructing invalid value at {$path}
439439

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
382382
}
383383

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

409411
Ok(())
410412
}
411413

412414
#[inline(always)]
413-
pub fn const_report_error<'mir, 'tcx>(
415+
fn report_validation_error<'mir, 'tcx>(
414416
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
415417
error: InterpErrorInfo<'tcx>,
416418
alloc_id: AllocId,
@@ -429,6 +431,6 @@ pub fn const_report_error<'mir, 'tcx>(
429431
error,
430432
None,
431433
|| crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()),
432-
move |span, frames| errors::UndefinedBehavior { span, ub_note, frames, raw_bytes },
434+
move |span, frames| errors::ValidationFailure { span, ub_note, frames, raw_bytes },
433435
)
434436
}

compiler/rustc_const_eval/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ pub struct NullaryIntrinsicError {
412412
}
413413

414414
#[derive(Diagnostic)]
415-
#[diag(const_eval_undefined_behavior, code = E0080)]
416-
pub struct UndefinedBehavior {
415+
#[diag(const_eval_validation_failure, code = E0080)]
416+
pub struct ValidationFailure {
417417
#[primary_span]
418418
pub span: Span,
419-
#[note(const_eval_undefined_behavior_note)]
419+
#[note(const_eval_validation_failure_note)]
420420
pub ub_note: Option<()>,
421421
#[subdiagnostic]
422422
pub frames: Vec<FrameNote>,

0 commit comments

Comments
 (0)