diff options
| author | Ralf Jung <post@ralfj.de> | 2023-11-26 18:21:56 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-12-07 17:46:36 +0100 |
| commit | 29c95e98e318be711169862c996982c7dffd2372 (patch) | |
| tree | 0e822c28cc59b868e120c997f89906f4c1af9255 /compiler/rustc_middle/src/mir/interpret/pointer.rs | |
| parent | 4d93590d59ca7d71ac401ce600fd0fe458a6375e (diff) | |
| download | rust-29c95e98e318be711169862c996982c7dffd2372.tar.gz rust-29c95e98e318be711169862c996982c7dffd2372.zip | |
also print 'immutable' flag
Diffstat (limited to 'compiler/rustc_middle/src/mir/interpret/pointer.rs')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/pointer.rs | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/pointer.rs b/compiler/rustc_middle/src/mir/interpret/pointer.rs index a7f54aacdf2..6893387736a 100644 --- a/compiler/rustc_middle/src/mir/interpret/pointer.rs +++ b/compiler/rustc_middle/src/mir/interpret/pointer.rs @@ -114,22 +114,7 @@ pub trait Provenance: Copy + fmt::Debug + 'static { const OFFSET_IS_ADDR: bool; /// Determines how a pointer should be printed. - /// - /// Default impl is only good for when `OFFSET_IS_ADDR == true`. - fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result - where - Self: Sized, - { - assert!(Self::OFFSET_IS_ADDR); - let (prov, addr) = ptr.into_parts(); // address is absolute - write!(f, "{:#x}", addr.bytes())?; - if f.alternate() { - write!(f, "{prov:#?}")?; - } else { - write!(f, "{prov:?}")?; - } - Ok(()) - } + fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result; /// If `OFFSET_IS_ADDR == false`, provenance must always be able to /// identify the allocation this ptr points to (i.e., this must return `Some`). @@ -156,8 +141,11 @@ impl From<AllocId> for CtfeProvenance { impl fmt::Debug for CtfeProvenance { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // FIXME print "immutable" bit - self.alloc_id().fmt(f) + fmt::Debug::fmt(&self.alloc_id(), f)?; // propagates `alternate` flag + if self.immutable() { + write!(f, "<imm>")?; + } + Ok(()) } } @@ -189,17 +177,16 @@ impl Provenance for CtfeProvenance { const OFFSET_IS_ADDR: bool = false; fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // FIXME print "immutable" bit - // Forward `alternate` flag to `alloc_id` printing. - if f.alternate() { - write!(f, "{:#?}", ptr.provenance.alloc_id())?; - } else { - write!(f, "{:?}", ptr.provenance.alloc_id())?; - } + // Print AllocId. + fmt::Debug::fmt(&ptr.provenance.alloc_id(), f)?; // propagates `alternate` flag // Print offset only if it is non-zero. if ptr.offset.bytes() > 0 { write!(f, "+{:#x}", ptr.offset.bytes())?; } + // Print immutable status. + if ptr.provenance.immutable() { + write!(f, "<imm>")?; + } Ok(()) } |
