format pointer later instead of eagerly converting to string
This commit is contained in:
parent
3f2dc2bd1a
commit
44b38ca45e
2 changed files with 15 additions and 15 deletions
|
|
@ -11,8 +11,8 @@ use rustc_span::{Span, Symbol};
|
|||
use super::CompileTimeMachine;
|
||||
use crate::errors::{self, FrameNote, ReportErrorExt};
|
||||
use crate::interpret::{
|
||||
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
|
||||
err_machine_stop,
|
||||
CtfeProvenance, ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType,
|
||||
Pointer, err_inval, err_machine_stop,
|
||||
};
|
||||
|
||||
/// The CTFE machine has some custom error kinds.
|
||||
|
|
@ -32,12 +32,12 @@ pub enum ConstEvalErrKind {
|
|||
/// Called `const_make_global` twice.
|
||||
ConstMakeGlobalPtrAlreadyMadeGlobal(AllocId),
|
||||
/// Called `const_make_global` on a non-heap pointer.
|
||||
ConstMakeGlobalPtrIsNonHeap(String),
|
||||
ConstMakeGlobalPtrIsNonHeap(Pointer<Option<CtfeProvenance>>),
|
||||
/// Called `const_make_global` on a dangling pointer.
|
||||
ConstMakeGlobalWithDanglingPtr(String),
|
||||
ConstMakeGlobalWithDanglingPtr(Pointer<Option<CtfeProvenance>>),
|
||||
/// Called `const_make_global` on a pointer that does not start at the
|
||||
/// beginning of an object.
|
||||
ConstMakeGlobalWithOffset(String),
|
||||
ConstMakeGlobalWithOffset(Pointer<Option<CtfeProvenance>>),
|
||||
}
|
||||
|
||||
impl MachineStopType for ConstEvalErrKind {
|
||||
|
|
@ -74,7 +74,7 @@ impl MachineStopType for ConstEvalErrKind {
|
|||
ConstMakeGlobalPtrIsNonHeap(ptr)
|
||||
| ConstMakeGlobalWithOffset(ptr)
|
||||
| ConstMakeGlobalWithDanglingPtr(ptr) => {
|
||||
adder("ptr".into(), ptr.into_diag_arg(&mut None));
|
||||
adder("ptr".into(), format!("{ptr:?}").into_diag_arg(&mut None));
|
||||
}
|
||||
ConstMakeGlobalPtrAlreadyMadeGlobal(alloc) => {
|
||||
adder("alloc".into(), alloc.into_diag_arg(&mut None));
|
||||
|
|
|
|||
|
|
@ -315,33 +315,33 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
/// mark the `const_allocate`d pointer immutable so we can intern it.
|
||||
pub fn make_const_heap_ptr_global(
|
||||
&mut self,
|
||||
ptr: Pointer<Option<M::Provenance>>,
|
||||
ptr: Pointer<Option<CtfeProvenance>>,
|
||||
) -> InterpResult<'tcx>
|
||||
where
|
||||
M: Machine<'tcx, MemoryKind = crate::const_eval::MemoryKind>,
|
||||
M: Machine<'tcx, MemoryKind = crate::const_eval::MemoryKind, Provenance = CtfeProvenance>,
|
||||
{
|
||||
let (alloc_id, offset, _) = self.ptr_get_alloc_id(ptr, 0)?;
|
||||
if offset.bytes() != 0 {
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(format!("{ptr:?}"))).into();
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(ptr)).into();
|
||||
}
|
||||
|
||||
let not_local_heap =
|
||||
matches!(self.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_)));
|
||||
|
||||
if not_local_heap {
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(format!("{ptr:?}"))).into();
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
|
||||
}
|
||||
|
||||
let (kind, alloc) = self.memory.alloc_map.get_mut_or(alloc_id, || {
|
||||
Err(ConstEvalErrKind::ConstMakeGlobalWithDanglingPtr(format!("{ptr:?}")))
|
||||
})?;
|
||||
let (kind, alloc) = self
|
||||
.memory
|
||||
.alloc_map
|
||||
.get_mut_or(alloc_id, || Err(ConstEvalErrKind::ConstMakeGlobalWithDanglingPtr(ptr)))?;
|
||||
|
||||
alloc.mutability = Mutability::Not;
|
||||
|
||||
match kind {
|
||||
MemoryKind::Stack | MemoryKind::CallerLocation => {
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(format!("{ptr:?}")))
|
||||
.into();
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
|
||||
}
|
||||
MemoryKind::Machine(crate::const_eval::MemoryKind::Heap { was_made_global }) => {
|
||||
if *was_made_global {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue