diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 8875baad58c..23e39f433f5 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -79,7 +79,7 @@ fn get_mut(&mut self, k: K) -> Option<&mut V> { /// and some use case dependent behaviour can instead be applied. pub trait Machine<'mir, 'tcx>: Sized { /// Additional memory kinds a machine wishes to distinguish from the builtin ones - type MemoryKind: ::std::fmt::Debug + MayLeak + Eq + 'static; + type MemoryKind: ::std::fmt::Debug + ::std::fmt::Display + MayLeak + Eq + 'static; /// Tag tracked alongside every pointer. This is used to implement "Stacked Borrows" /// . diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index e61b0796cc1..c16c59715e4 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -9,6 +9,7 @@ use std::borrow::Cow; use std::collections::VecDeque; use std::convert::TryFrom; +use std::fmt; use std::ptr; use rustc_ast::ast::Mutability; @@ -46,6 +47,17 @@ fn may_leak(self) -> bool { } } +impl fmt::Display for MemoryKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + MemoryKind::Stack => write!(f, "stack variable"), + MemoryKind::Vtable => write!(f, "vtable"), + MemoryKind::CallerLocation => write!(f, "caller location"), + MemoryKind::Machine(m) => write!(f, "{}", m), + } + } +} + /// Used by `get_size_and_align` to indicate whether the allocation needs to be live. #[derive(Debug, Copy, Clone)] pub enum AllocCheck { @@ -259,7 +271,7 @@ pub fn deallocate( if alloc_kind != kind { throw_ub_format!( - "deallocating `{:?}` memory using `{:?}` deallocation operation", + "deallocating {} memory using {} deallocation operation", alloc_kind, kind ); @@ -677,22 +689,14 @@ fn write_allocation_track_relocs<'tcx, Tag, Extra>( match self.alloc_map.get(id) { Some(&(kind, ref alloc)) => { // normal alloc - match kind { - MemoryKind::Stack => eprint!(" (stack variable, "), - MemoryKind::Vtable => eprint!(" (vtable, "), - MemoryKind::CallerLocation => eprint!(" (caller_location, "), - MemoryKind::Machine(m) if Some(m) == M::GLOBAL_KIND => { - eprint!(" (global, ") - } - MemoryKind::Machine(m) => eprint!(" ({:?}, ", m), - }; + eprint!(" ({}, ", kind); write_allocation_track_relocs(self.tcx, &mut allocs_to_print, alloc); } None => { // global alloc match self.tcx.alloc_map.lock().get(id) { Some(GlobalAlloc::Memory(alloc)) => { - eprint!(" (global, "); + eprint!(" (unchanged global, "); write_allocation_track_relocs(self.tcx, &mut allocs_to_print, alloc); } Some(GlobalAlloc::Function(func)) => {