Rollup merge of #101101 - RalfJung:read-pointer-as-bytes, r=oli-obk
interpret: make read-pointer-as-bytes a CTFE-only error with extra information Next step in the reaction to https://github.com/rust-lang/rust/issues/99923. Also teaches Miri to implicitly strip provenance in more situations when transmuting pointers to integers, which fixes https://github.com/rust-lang/miri/issues/2456. Pointer-to-int transmutation during CTFE now produces a message like this: ``` = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported ``` r? ``@oli-obk``
This commit is contained in:
@@ -10,6 +10,7 @@ use rustc_span::{Span, Symbol};
|
||||
use super::InterpCx;
|
||||
use crate::interpret::{
|
||||
struct_error, ErrorHandled, FrameInfo, InterpError, InterpErrorInfo, Machine, MachineStopType,
|
||||
UnsupportedOpInfo,
|
||||
};
|
||||
|
||||
/// The CTFE machine has some custom error kinds.
|
||||
@@ -149,6 +150,18 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||
if let Some(span_msg) = span_msg {
|
||||
err.span_label(self.span, span_msg);
|
||||
}
|
||||
// Add some more context for select error types.
|
||||
match self.error {
|
||||
InterpError::Unsupported(
|
||||
UnsupportedOpInfo::ReadPointerAsBytes
|
||||
| UnsupportedOpInfo::PartialPointerOverwrite(_)
|
||||
| UnsupportedOpInfo::PartialPointerCopy(_),
|
||||
) => {
|
||||
err.help("this code performed an operation that depends on the underlying bytes representing a pointer");
|
||||
err.help("the absolute address of a pointer is not known at compile-time, so such operations are not supported");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Add spans for the stacktrace. Don't print a single-line backtrace though.
|
||||
if self.stacktrace.len() > 1 {
|
||||
// Helper closure to print duplicated lines.
|
||||
|
||||
@@ -2,8 +2,8 @@ use super::{CompileTimeEvalContext, CompileTimeInterpreter, ConstEvalErr};
|
||||
use crate::interpret::eval_nullary_intrinsic;
|
||||
use crate::interpret::{
|
||||
intern_const_alloc_recursive, Allocation, ConstAlloc, ConstValue, CtfeValidationMode, GlobalId,
|
||||
Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
|
||||
StackPopCleanup,
|
||||
Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy,
|
||||
RefTracking, StackPopCleanup,
|
||||
};
|
||||
|
||||
use rustc_hir::def::DefKind;
|
||||
@@ -387,7 +387,9 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
|
||||
ecx.tcx,
|
||||
"it is undefined behavior to use this value",
|
||||
|diag| {
|
||||
diag.note(NOTE_ON_UNDEFINED_BEHAVIOR_ERROR);
|
||||
if matches!(err.error, InterpError::UndefinedBehavior(_)) {
|
||||
diag.note(NOTE_ON_UNDEFINED_BEHAVIOR_ERROR);
|
||||
}
|
||||
diag.note(&format!(
|
||||
"the raw bytes of the constant ({}",
|
||||
display_allocation(
|
||||
|
||||
Reference in New Issue
Block a user