From da0d4829bf7ca00fce64ce8563b84299699131b2 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 29 Aug 2022 17:14:45 -0400 Subject: [PATCH] Use the better FnEntry spans in protector errors --- rust-version | 2 +- src/diagnostics.rs | 3 +- src/machine.rs | 13 ++-- src/stacked_borrows/diagnostics.rs | 64 ++++++------------- src/stacked_borrows/mod.rs | 13 +++- .../fail/stacked_borrows/aliasing_mut1.stderr | 9 ++- .../fail/stacked_borrows/aliasing_mut2.stderr | 13 ++-- .../fail/stacked_borrows/aliasing_mut3.stderr | 8 +-- .../fail/stacked_borrows/aliasing_mut4.stderr | 13 ++-- tests/fail/stacked_borrows/illegal_write6.rs | 2 +- .../stacked_borrows/illegal_write6.stderr | 20 ++---- .../invalidate_against_protector1.stderr | 20 ++---- .../invalidate_against_protector2.stderr | 20 ++---- .../fail/stacked_borrows/newtype_retagging.rs | 2 +- .../stacked_borrows/newtype_retagging.stderr | 17 ++--- 15 files changed, 80 insertions(+), 139 deletions(-) diff --git a/rust-version b/rust-version index 9b8d986c671..f7e2fa5a33d 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -4065b89b1e7287047d7d6c65e7abd7b8ee70bcf0 +94b2b15e63c5d2b2a6a0910e3dae554ce9415bf9 diff --git a/src/diagnostics.rs b/src/diagnostics.rs index eafe56955d1..26442da6d65 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -183,9 +183,8 @@ pub fn report_error<'tcx, 'mir>( if let Some((msg, span)) = invalidated { helps.push((Some(span), msg)); } - if let Some([(protector_msg, protector_span), (protection_msg, protection_span)]) = protected { + if let Some((protector_msg, protector_span)) = protected { helps.push((Some(protector_span), protector_msg)); - helps.push((Some(protection_span), protection_msg)); } } helps diff --git a/src/machine.rs b/src/machine.rs index 0862b3b17c6..4f7e3a6a71b 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -743,10 +743,15 @@ fn adjust_allocation<'b>( } let alloc = alloc.into_owned(); - let stacks = - ecx.machine.stacked_borrows.as_ref().map(|stacked_borrows| { - Stacks::new_allocation(id, alloc.size(), stacked_borrows, kind) - }); + let stacks = ecx.machine.stacked_borrows.as_ref().map(|stacked_borrows| { + Stacks::new_allocation( + id, + alloc.size(), + stacked_borrows, + kind, + ecx.machine.current_span(*ecx.tcx), + ) + }); let race_alloc = ecx.machine.data_race.as_ref().map(|data_race| { data_race::AllocExtra::new_allocation( data_race, diff --git a/src/stacked_borrows/diagnostics.rs b/src/stacked_borrows/diagnostics.rs index 87f0ce74191..b8e777717e9 100644 --- a/src/stacked_borrows/diagnostics.rs +++ b/src/stacked_borrows/diagnostics.rs @@ -2,7 +2,7 @@ use std::fmt; use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange}; -use rustc_span::{Span, SpanData, DUMMY_SP}; +use rustc_span::{Span, SpanData}; use rustc_target::abi::Size; use crate::helpers::CurrentSpan; @@ -14,6 +14,7 @@ #[derive(Clone, Debug)] pub struct AllocHistory { id: AllocId, + base: (Item, Span), creations: smallvec::SmallVec<[Creation; 1]>, invalidations: smallvec::SmallVec<[Invalidation; 1]>, protectors: smallvec::SmallVec<[Protection; 1]>, @@ -91,8 +92,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[derive(Clone, Debug)] struct Protection { - /// The parent tag from which this protected tag was derived. - orig_tag: ProvenanceExtra, tag: SbTag, span: Span, } @@ -101,7 +100,7 @@ struct Protection { pub struct TagHistory { pub created: (String, SpanData), pub invalidated: Option<(String, SpanData)>, - pub protected: Option<([(String, SpanData); 2])>, + pub protected: Option<(String, SpanData)>, } pub struct DiagnosticCxBuilder<'span, 'ecx, 'mir, 'tcx> { @@ -228,9 +227,10 @@ struct DeallocOp { } impl AllocHistory { - pub fn new(id: AllocId) -> Self { + pub fn new(id: AllocId, item: Item, current_span: &mut CurrentSpan<'_, '_, '_>) -> Self { Self { id, + base: (item, current_span.get()), creations: SmallVec::new(), invalidations: SmallVec::new(), protectors: SmallVec::new(), @@ -290,11 +290,7 @@ pub fn log_protector(&mut self) { let Operation::Retag(op) = &self.operation else { unreachable!("Protectors can only be created during a retag") }; - self.history.protectors.push(Protection { - orig_tag: op.orig_tag, - tag: op.new_tag, - span: self.current_span.get(), - }); + self.history.protectors.push(Protection { tag: op.new_tag, span: self.current_span.get() }); } pub fn get_logs_relevant_to( @@ -331,6 +327,17 @@ pub fn get_logs_relevant_to( None } }) + }).or_else(|| { + // If we didn't find a retag that created this tag, it might be the base tag of + // this allocation. + if self.history.base.0.tag() == tag { + Some(( + format!("{:?} was created here, as a base tag for {:?}", tag, self.history.id), + self.history.base.1.data() + )) + } else { + None + } }) else { // But if we don't have a creation event, this is related to a wildcard, and there // is really nothing we can do to help. @@ -343,40 +350,11 @@ pub fn get_logs_relevant_to( let protected = protector_tag .and_then(|protector| { - self.history.protectors.iter().find(|protection| { - protection.tag == protector - }) + self.history.protectors.iter().find(|protection| protection.tag == protector) }) - .and_then(|protection| { - self.history.creations.iter().rev().find_map(|event| { - if ProvenanceExtra::Concrete(event.retag.new_tag) == protection.orig_tag { - Some((protection, event)) - } else { - None - } - }) - }) - .map(|(protection, protection_parent)| { + .map(|protection| { let protected_tag = protection.tag; - [ - ( - format!( - "{tag:?} cannot be used for memory access because that would remove protected tag {protected_tag:?}, protected by this function call", - ), - protection.span.data(), - ), - if protection_parent.retag.new_tag == tag { - (format!("{protected_tag:?} was derived from {tag:?}, the tag used for this memory access"), DUMMY_SP.data()) - } else { - ( - format!( - "{protected_tag:?} was derived from {protected_parent_tag:?}, which in turn was created here", - protected_parent_tag = protection_parent.retag.new_tag, - ), - protection_parent.span.data() - ) - } - ] + (format!("{protected_tag:?} is this argument"), protection.span.data()) }); Some(TagHistory { created, invalidated, protected }) @@ -448,7 +426,7 @@ pub fn protector_error(&self, item: &Item) -> InterpError<'tcx> { | Operation::Access(AccessOp { tag, .. }) => err_sb_ub( format!( - "not granting access to tag {:?} because incompatible item {:?} is protected by call {:?}", + "not granting access to tag {:?} because that would remove {:?} which is protected because it is an argument of call {:?}", tag, item, call_id ), None, diff --git a/src/stacked_borrows/mod.rs b/src/stacked_borrows/mod.rs index 5cdcaecc17d..4f7914c5fb0 100644 --- a/src/stacked_borrows/mod.rs +++ b/src/stacked_borrows/mod.rs @@ -500,13 +500,19 @@ fn grant( impl<'tcx> Stacks { /// Creates a new stack with an initial tag. For diagnostic purposes, we also need to know /// the [`AllocId`] of the allocation this is associated with. - fn new(size: Size, perm: Permission, tag: SbTag, id: AllocId) -> Self { + fn new( + size: Size, + perm: Permission, + tag: SbTag, + id: AllocId, + current_span: &mut CurrentSpan<'_, '_, '_>, + ) -> Self { let item = Item::new(tag, perm, false); let stack = Stack::new(item); Stacks { stacks: RangeMap::new(size, stack), - history: AllocHistory::new(id), + history: AllocHistory::new(id, item, current_span), exposed_tags: FxHashSet::default(), } } @@ -538,6 +544,7 @@ pub fn new_allocation( size: Size, state: &GlobalState, kind: MemoryKind, + mut current_span: CurrentSpan<'_, '_, '_>, ) -> Self { let mut extra = state.borrow_mut(); let (base_tag, perm) = match kind { @@ -550,7 +557,7 @@ pub fn new_allocation( // Everything else is shared by default. _ => (extra.base_ptr_tag(id), Permission::SharedReadWrite), }; - Stacks::new(size, perm, base_tag, id) + Stacks::new(size, perm, base_tag, id, &mut current_span) } #[inline(always)] diff --git a/tests/fail/stacked_borrows/aliasing_mut1.stderr b/tests/fail/stacked_borrows/aliasing_mut1.stderr index e5be3061b32..514b1a9901e 100644 --- a/tests/fail/stacked_borrows/aliasing_mut1.stderr +++ b/tests/fail/stacked_borrows/aliasing_mut1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [Unique for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID --> $DIR/aliasing_mut1.rs:LL:CC | LL | pub fn safe(_x: &mut i32, _y: &mut i32) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag because incompatible item [Unique for ] is protected by call ID + | ^^ not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,12 +11,11 @@ help: was created by a Unique retag at offsets [0x0..0x4] | LL | let xraw: *mut i32 = unsafe { mem::transmute(&mut x) }; | ^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/aliasing_mut1.rs:LL:CC | LL | pub fn safe(_x: &mut i32, _y: &mut i32) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: was derived from , the tag used for this memory access + | ^^ = note: backtrace: = note: inside `safe` at $DIR/aliasing_mut1.rs:LL:CC note: inside `main` at $DIR/aliasing_mut1.rs:LL:CC diff --git a/tests/fail/stacked_borrows/aliasing_mut2.stderr b/tests/fail/stacked_borrows/aliasing_mut2.stderr index c3dd3a893c0..5fc56a91f57 100644 --- a/tests/fail/stacked_borrows/aliasing_mut2.stderr +++ b/tests/fail/stacked_borrows/aliasing_mut2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID --> $DIR/aliasing_mut2.rs:LL:CC | LL | pub fn safe(_x: &i32, _y: &mut i32) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID + | ^^ not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,16 +11,11 @@ help: was created by a Unique retag at offsets [0x0..0x4] | LL | let xref = &mut x; | ^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/aliasing_mut2.rs:LL:CC | LL | pub fn safe(_x: &i32, _y: &mut i32) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: was derived from , which in turn was created here - --> $DIR/aliasing_mut2.rs:LL:CC - | -LL | safe_raw(xshr, xraw); - | ^^^^ + | ^^ = note: backtrace: = note: inside `safe` at $DIR/aliasing_mut2.rs:LL:CC note: inside `main` at $DIR/aliasing_mut2.rs:LL:CC diff --git a/tests/fail/stacked_borrows/aliasing_mut3.stderr b/tests/fail/stacked_borrows/aliasing_mut3.stderr index 0fa31260323..ee38ea41700 100644 --- a/tests/fail/stacked_borrows/aliasing_mut3.stderr +++ b/tests/fail/stacked_borrows/aliasing_mut3.stderr @@ -2,10 +2,10 @@ error: Undefined Behavior: trying to retag from for SharedReadOnly permiss --> $DIR/aliasing_mut3.rs:LL:CC | LL | pub fn safe(_x: &mut i32, _y: &i32) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location - | this error occurs as part of FnEntry retag at ALLOC[0x0..0x4] + | ^^ + | | + | trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location + | this error occurs as part of FnEntry retag at ALLOC[0x0..0x4] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information diff --git a/tests/fail/stacked_borrows/aliasing_mut4.stderr b/tests/fail/stacked_borrows/aliasing_mut4.stderr index 601422ece30..d5c2e736696 100644 --- a/tests/fail/stacked_borrows/aliasing_mut4.stderr +++ b/tests/fail/stacked_borrows/aliasing_mut4.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID --> $DIR/aliasing_mut4.rs:LL:CC | LL | pub fn safe(_x: &i32, _y: &mut Cell) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID + | ^^ not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,16 +11,11 @@ help: was created by a Unique retag at offsets [0x0..0x4] | LL | let xref = &mut x; | ^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/aliasing_mut4.rs:LL:CC | LL | pub fn safe(_x: &i32, _y: &mut Cell) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: was derived from , which in turn was created here - --> $DIR/aliasing_mut4.rs:LL:CC - | -LL | safe_raw(xshr, xraw as *mut _); - | ^^^^ + | ^^ = note: backtrace: = note: inside `safe` at $DIR/aliasing_mut4.rs:LL:CC note: inside `main` at $DIR/aliasing_mut4.rs:LL:CC diff --git a/tests/fail/stacked_borrows/illegal_write6.rs b/tests/fail/stacked_borrows/illegal_write6.rs index 1e032840917..448f1493367 100644 --- a/tests/fail/stacked_borrows/illegal_write6.rs +++ b/tests/fail/stacked_borrows/illegal_write6.rs @@ -7,6 +7,6 @@ fn main() { fn foo(a: &mut u32, y: *mut u32) -> u32 { *a = 1; let _b = &*a; - unsafe { *y = 2 }; //~ ERROR: /not granting access .* because incompatible item .* is protected/ + unsafe { *y = 2 }; //~ ERROR: /not granting access .* because that would remove .* which is protected/ return *a; } diff --git a/tests/fail/stacked_borrows/illegal_write6.stderr b/tests/fail/stacked_borrows/illegal_write6.stderr index fd3b19adcf5..56e4bd79d47 100644 --- a/tests/fail/stacked_borrows/illegal_write6.stderr +++ b/tests/fail/stacked_borrows/illegal_write6.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [Unique for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID --> $DIR/illegal_write6.rs:LL:CC | LL | unsafe { *y = 2 }; - | ^^^^^^ not granting access to tag because incompatible item [Unique for ] is protected by call ID + | ^^^^^^ not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,21 +11,11 @@ help: was created by a SharedReadWrite retag at offsets [0x0..0x4] | LL | let p = x as *mut u32; | ^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/illegal_write6.rs:LL:CC | -LL | / fn foo(a: &mut u32, y: *mut u32) -> u32 { -LL | | *a = 1; -LL | | let _b = &*a; -LL | | unsafe { *y = 2 }; -LL | | return *a; -LL | | } - | |_^ -help: was derived from , which in turn was created here - --> $DIR/illegal_write6.rs:LL:CC - | -LL | foo(x, p); - | ^ +LL | fn foo(a: &mut u32, y: *mut u32) -> u32 { + | ^ = note: backtrace: = note: inside `foo` at $DIR/illegal_write6.rs:LL:CC note: inside `main` at $DIR/illegal_write6.rs:LL:CC diff --git a/tests/fail/stacked_borrows/invalidate_against_protector1.stderr b/tests/fail/stacked_borrows/invalidate_against_protector1.stderr index 18236adec88..5e6fd6e0275 100644 --- a/tests/fail/stacked_borrows/invalidate_against_protector1.stderr +++ b/tests/fail/stacked_borrows/invalidate_against_protector1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [Unique for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID --> $DIR/invalidate_against_protector1.rs:LL:CC | LL | let _val = unsafe { *x }; - | ^^ not granting access to tag because incompatible item [Unique for ] is protected by call ID + | ^^ not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,21 +11,11 @@ help: was created by a SharedReadWrite retag at offsets [0x0..0x4] | LL | let xraw = &mut x as *mut _; | ^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/invalidate_against_protector1.rs:LL:CC | -LL | / fn inner(x: *mut i32, _y: &mut i32) { -LL | | // If `x` and `y` alias, retagging is fine with this... but we really -LL | | // shouldn't be allowed to use `x` at all because `y` was assumed to be -LL | | // unique for the duration of this call. -LL | | let _val = unsafe { *x }; -LL | | } - | |_^ -help: was derived from , which in turn was created here - --> $DIR/invalidate_against_protector1.rs:LL:CC - | -LL | inner(xraw, xref); - | ^^^^ +LL | fn inner(x: *mut i32, _y: &mut i32) { + | ^^ = note: backtrace: = note: inside `inner` at $DIR/invalidate_against_protector1.rs:LL:CC note: inside `main` at $DIR/invalidate_against_protector1.rs:LL:CC diff --git a/tests/fail/stacked_borrows/invalidate_against_protector2.stderr b/tests/fail/stacked_borrows/invalidate_against_protector2.stderr index 20b9d47bbef..eab55d2568d 100644 --- a/tests/fail/stacked_borrows/invalidate_against_protector2.stderr +++ b/tests/fail/stacked_borrows/invalidate_against_protector2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID --> $DIR/invalidate_against_protector2.rs:LL:CC | LL | unsafe { *x = 0 }; - | ^^^^^^ not granting access to tag because incompatible item [SharedReadOnly for ] is protected by call ID + | ^^^^^^ not granting access to tag because that would remove [SharedReadOnly for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,21 +11,11 @@ help: was created by a SharedReadWrite retag at offsets [0x0..0x4] | LL | let xraw = &mut x as *mut _; | ^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/invalidate_against_protector2.rs:LL:CC | -LL | / fn inner(x: *mut i32, _y: &i32) { -LL | | // If `x` and `y` alias, retagging is fine with this... but we really -LL | | // shouldn't be allowed to write to `x` at all because `y` was assumed to be -LL | | // immutable for the duration of this call. -LL | | unsafe { *x = 0 }; -LL | | } - | |_^ -help: was derived from , which in turn was created here - --> $DIR/invalidate_against_protector2.rs:LL:CC - | -LL | inner(xraw, xref); - | ^^^^ +LL | fn inner(x: *mut i32, _y: &i32) { + | ^^ = note: backtrace: = note: inside `inner` at $DIR/invalidate_against_protector2.rs:LL:CC note: inside `main` at $DIR/invalidate_against_protector2.rs:LL:CC diff --git a/tests/fail/stacked_borrows/newtype_retagging.rs b/tests/fail/stacked_borrows/newtype_retagging.rs index f9cceb761af..6e7413cff5d 100644 --- a/tests/fail/stacked_borrows/newtype_retagging.rs +++ b/tests/fail/stacked_borrows/newtype_retagging.rs @@ -1,5 +1,5 @@ //@compile-flags: -Zmiri-retag-fields -//@error-pattern: is protected by call +//@error-pattern: which is protected struct Newtype<'a>(&'a mut i32); fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) { diff --git a/tests/fail/stacked_borrows/newtype_retagging.stderr b/tests/fail/stacked_borrows/newtype_retagging.stderr index e75502d3610..7073c8162d1 100644 --- a/tests/fail/stacked_borrows/newtype_retagging.stderr +++ b/tests/fail/stacked_borrows/newtype_retagging.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: not granting access to tag because incompatible item [Unique for ] is protected by call ID +error: Undefined Behavior: not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID --> RUSTLIB/alloc/src/boxed.rs:LL:CC | LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag because incompatible item [Unique for ] is protected by call ID + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag because that would remove [Unique for ] which is protected because it is an argument of call ID | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information @@ -11,18 +11,11 @@ help: was created by a SharedReadWrite retag at offsets [0x0..0x4] | LL | let ptr = Box::into_raw(Box::new(0i32)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: cannot be used for memory access because that would remove protected tag , protected by this function call +help: is this argument --> $DIR/newtype_retagging.rs:LL:CC | -LL | / fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) { -LL | | dealloc(); -LL | | } - | |_^ -help: was derived from , which in turn was created here - --> $DIR/newtype_retagging.rs:LL:CC - | -LL | Newtype(&mut *ptr), - | ^^^^^^^^^^^^^^^^^^ +LL | fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) { + | ^^ = note: backtrace: = note: inside `std::boxed::Box::::from_raw_in` at RUSTLIB/alloc/src/boxed.rs:LL:CC = note: inside `std::boxed::Box::::from_raw` at RUSTLIB/alloc/src/boxed.rs:LL:CC -- 2.44.0