Skip to content

Commit 6fddbb8

Browse files
committed
format pointer later instead of eagerly converting to string
1 parent c5ec462 commit 6fddbb8

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_span::{Span, Symbol};
1111
use super::CompileTimeMachine;
1212
use crate::errors::{self, FrameNote, ReportErrorExt};
1313
use crate::interpret::{
14-
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
15-
err_machine_stop,
14+
CtfeProvenance, ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType,
15+
Pointer, err_inval, err_machine_stop,
1616
};
1717

1818
/// The CTFE machine has some custom error kinds.
@@ -32,12 +32,12 @@ pub enum ConstEvalErrKind {
3232
/// Called `const_make_global` twice.
3333
ConstMakeGlobalPtrAlreadyMadeGlobal(AllocId),
3434
/// Called `const_make_global` on a non-heap pointer.
35-
ConstMakeGlobalPtrIsNonHeap(String),
35+
ConstMakeGlobalPtrIsNonHeap(Pointer<Option<CtfeProvenance>>),
3636
/// Called `const_make_global` on a dangling pointer.
37-
ConstMakeGlobalWithDanglingPtr(String),
37+
ConstMakeGlobalWithDanglingPtr(Pointer<Option<CtfeProvenance>>),
3838
/// Called `const_make_global` on a pointer that does not start at the
3939
/// beginning of an object.
40-
ConstMakeGlobalWithOffset(String),
40+
ConstMakeGlobalWithOffset(Pointer<Option<CtfeProvenance>>),
4141
}
4242

4343
impl MachineStopType for ConstEvalErrKind {
@@ -74,7 +74,7 @@ impl MachineStopType for ConstEvalErrKind {
7474
ConstMakeGlobalPtrIsNonHeap(ptr)
7575
| ConstMakeGlobalWithOffset(ptr)
7676
| ConstMakeGlobalWithDanglingPtr(ptr) => {
77-
adder("ptr".into(), ptr.into_diag_arg(&mut None));
77+
adder("ptr".into(), format!("{ptr:?}").into_diag_arg(&mut None));
7878
}
7979
ConstMakeGlobalPtrAlreadyMadeGlobal(alloc) => {
8080
adder("alloc".into(), alloc.into_diag_arg(&mut None));

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,33 +315,33 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
315315
/// mark the `const_allocate`d pointer immutable so we can intern it.
316316
pub fn make_const_heap_ptr_global(
317317
&mut self,
318-
ptr: Pointer<Option<M::Provenance>>,
318+
ptr: Pointer<Option<CtfeProvenance>>,
319319
) -> InterpResult<'tcx>
320320
where
321-
M: Machine<'tcx, MemoryKind = crate::const_eval::MemoryKind>,
321+
M: Machine<'tcx, MemoryKind = crate::const_eval::MemoryKind, Provenance = CtfeProvenance>,
322322
{
323323
let (alloc_id, offset, _) = self.ptr_get_alloc_id(ptr, 0)?;
324324
if offset.bytes() != 0 {
325-
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(format!("{ptr:?}"))).into();
325+
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(ptr)).into();
326326
}
327327

328328
let not_local_heap =
329329
matches!(self.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_)));
330330

331331
if not_local_heap {
332-
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(format!("{ptr:?}"))).into();
332+
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
333333
}
334334

335-
let (kind, alloc) = self.memory.alloc_map.get_mut_or(alloc_id, || {
336-
Err(ConstEvalErrKind::ConstMakeGlobalWithDanglingPtr(format!("{ptr:?}")))
337-
})?;
335+
let (kind, alloc) = self
336+
.memory
337+
.alloc_map
338+
.get_mut_or(alloc_id, || Err(ConstEvalErrKind::ConstMakeGlobalWithDanglingPtr(ptr)))?;
338339

339340
alloc.mutability = Mutability::Not;
340341

341342
match kind {
342343
MemoryKind::Stack | MemoryKind::CallerLocation => {
343-
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(format!("{ptr:?}")))
344-
.into();
344+
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
345345
}
346346
MemoryKind::Machine(crate::const_eval::MemoryKind::Heap { was_made_global }) => {
347347
if *was_made_global {

0 commit comments

Comments
 (0)