Skip to content

Commit 9b57e5f

Browse files
committed
tweak wording
1 parent 594cd33 commit 9b57e5f

File tree

8 files changed

+60
-56
lines changed

8 files changed

+60
-56
lines changed

src/stacked_borrows/diagnostics.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use smallvec::SmallVec;
22
use std::fmt;
33

44
use rustc_middle::mir::interpret::{alloc_range, AllocId, AllocRange};
5-
use rustc_span::{Span, SpanData};
5+
use rustc_span::{Span, SpanData, DUMMY_SP};
66
use rustc_target::abi::Size;
77

88
use crate::helpers::CurrentSpan;
@@ -91,6 +91,7 @@ impl fmt::Display for InvalidationCause {
9191

9292
#[derive(Clone, Debug)]
9393
struct Protection {
94+
/// The parent tag from which this protected tag was derived.
9495
orig_tag: ProvenanceExtra,
9596
tag: SbTag,
9697
span: Span,
@@ -342,32 +343,39 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
342343

343344
let protected = protector_tag
344345
.and_then(|protector| {
345-
self.history.protectors.iter().find_map(|protection| {
346-
if protection.tag == protector {
347-
Some((protection.orig_tag, protection.span.data()))
348-
} else {
349-
None
350-
}
346+
self.history.protectors.iter().find(|protection| {
347+
protection.tag == protector
351348
})
352349
})
353-
.and_then(|(tag, call_span)| {
350+
.and_then(|protection| {
354351
self.history.creations.iter().rev().find_map(|event| {
355-
if ProvenanceExtra::Concrete(event.retag.new_tag) == tag {
356-
Some((event.retag.orig_tag, event.span.data(), call_span))
352+
if ProvenanceExtra::Concrete(event.retag.new_tag) == protection.orig_tag {
353+
Some((protection, event))
357354
} else {
358355
None
359356
}
360357
})
361358
})
362-
.map(|(protected_tag, protected_tag_span, protecting_call_span)| {
359+
.map(|(protection, protection_parent)| {
360+
let protected_tag = protection.tag;
363361
[
364362
(
365363
format!(
366-
"{tag:?} cannot be activated because of protected derived tag {protected_tag:?} which was created here"
364+
"{tag:?} cannot be used for memory access because that would remove protected tag {protected_tag:?}, protected by this function call",
367365
),
368-
protected_tag_span,
366+
protection.span.data(),
369367
),
370-
(format!("{protected_tag:?} is protected for the duration of this call"), protecting_call_span),
368+
if protection_parent.retag.new_tag == tag {
369+
(format!("{protected_tag:?} was derived from {tag:?}, the tag used for this memory access"), DUMMY_SP.data())
370+
} else {
371+
(
372+
format!(
373+
"{protected_tag:?} was derived from {protected_parent_tag:?}, which in turn was created here",
374+
protected_parent_tag = protection_parent.retag.new_tag,
375+
),
376+
protection_parent.span.data()
377+
)
378+
}
371379
]
372380
});
373381

tests/fail/stacked_borrows/aliasing_mut1.stderr

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
1111
|
1212
LL | let xraw: *mut i32 = unsafe { mem::transmute(&mut x) };
1313
| ^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/aliasing_mut1.rs:LL:CC
16-
|
17-
LL | let xraw: *mut i32 = unsafe { mem::transmute(&mut x) };
18-
| ^^^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/aliasing_mut1.rs:LL:CC
2116
|
2217
LL | pub fn safe(_x: &mut i32, _y: &mut i32) {}
2318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
= help: <TAG> was derived from <TAG>, the tag used for this memory access
2420
= note: backtrace:
2521
= note: inside `safe` at $DIR/aliasing_mut1.rs:LL:CC
2622
note: inside `main` at $DIR/aliasing_mut1.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut2.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
1111
|
1212
LL | let xref = &mut x;
1313
| ^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/aliasing_mut2.rs:LL:CC
16-
|
17-
LL | safe_raw(xshr, xraw);
18-
| ^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/aliasing_mut2.rs:LL:CC
2116
|
2217
LL | pub fn safe(_x: &i32, _y: &mut i32) {}
2318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
help: <TAG> was derived from <TAG>, which in turn was created here
20+
--> $DIR/aliasing_mut2.rs:LL:CC
21+
|
22+
LL | safe_raw(xshr, xraw);
23+
| ^^^^
2424
= note: backtrace:
2525
= note: inside `safe` at $DIR/aliasing_mut2.rs:LL:CC
2626
note: inside `main` at $DIR/aliasing_mut2.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut4.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
1111
|
1212
LL | let xref = &mut x;
1313
| ^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/aliasing_mut4.rs:LL:CC
16-
|
17-
LL | safe_raw(xshr, xraw as *mut _);
18-
| ^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/aliasing_mut4.rs:LL:CC
2116
|
2217
LL | pub fn safe(_x: &i32, _y: &mut Cell<i32>) {}
2318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
help: <TAG> was derived from <TAG>, which in turn was created here
20+
--> $DIR/aliasing_mut4.rs:LL:CC
21+
|
22+
LL | safe_raw(xshr, xraw as *mut _);
23+
| ^^^^
2424
= note: backtrace:
2525
= note: inside `safe` at $DIR/aliasing_mut4.rs:LL:CC
2626
note: inside `main` at $DIR/aliasing_mut4.rs:LL:CC

tests/fail/stacked_borrows/illegal_write6.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1111
|
1212
LL | let p = x as *mut u32;
1313
| ^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/illegal_write6.rs:LL:CC
16-
|
17-
LL | foo(x, p);
18-
| ^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/illegal_write6.rs:LL:CC
2116
|
2217
LL | / fn foo(a: &mut u32, y: *mut u32) -> u32 {
@@ -26,6 +21,11 @@ LL | | unsafe { *y = 2 };
2621
LL | | return *a;
2722
LL | | }
2823
| |_^
24+
help: <TAG> was derived from <TAG>, which in turn was created here
25+
--> $DIR/illegal_write6.rs:LL:CC
26+
|
27+
LL | foo(x, p);
28+
| ^
2929
= note: backtrace:
3030
= note: inside `foo` at $DIR/illegal_write6.rs:LL:CC
3131
note: inside `main` at $DIR/illegal_write6.rs:LL:CC

tests/fail/stacked_borrows/invalidate_against_barrier1.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1111
|
1212
LL | let xraw = &mut x as *mut _;
1313
| ^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/invalidate_against_barrier1.rs:LL:CC
16-
|
17-
LL | inner(xraw, xref);
18-
| ^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/invalidate_against_barrier1.rs:LL:CC
2116
|
2217
LL | / fn inner(x: *mut i32, _y: &mut i32) {
@@ -26,6 +21,11 @@ LL | | // unique for the duration of this call.
2621
LL | | let _val = unsafe { *x };
2722
LL | | }
2823
| |_^
24+
help: <TAG> was derived from <TAG>, which in turn was created here
25+
--> $DIR/invalidate_against_barrier1.rs:LL:CC
26+
|
27+
LL | inner(xraw, xref);
28+
| ^^^^
2929
= note: backtrace:
3030
= note: inside `inner` at $DIR/invalidate_against_barrier1.rs:LL:CC
3131
note: inside `main` at $DIR/invalidate_against_barrier1.rs:LL:CC

tests/fail/stacked_borrows/invalidate_against_barrier2.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1111
|
1212
LL | let xraw = &mut x as *mut _;
1313
| ^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/invalidate_against_barrier2.rs:LL:CC
16-
|
17-
LL | inner(xraw, xref);
18-
| ^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/invalidate_against_barrier2.rs:LL:CC
2116
|
2217
LL | / fn inner(x: *mut i32, _y: &i32) {
@@ -26,6 +21,11 @@ LL | | // immutable for the duration of this call.
2621
LL | | unsafe { *x = 0 };
2722
LL | | }
2823
| |_^
24+
help: <TAG> was derived from <TAG>, which in turn was created here
25+
--> $DIR/invalidate_against_barrier2.rs:LL:CC
26+
|
27+
LL | inner(xraw, xref);
28+
| ^^^^
2929
= note: backtrace:
3030
= note: inside `inner` at $DIR/invalidate_against_barrier2.rs:LL:CC
3131
note: inside `main` at $DIR/invalidate_against_barrier2.rs:LL:CC

tests/fail/stacked_borrows/newtype_retagging.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1111
|
1212
LL | let ptr = Box::into_raw(Box::new(0i32));
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
help: <TAG> cannot be activated because of protected derived tag <TAG> which was created here
15-
--> $DIR/newtype_retagging.rs:LL:CC
16-
|
17-
LL | Newtype(&mut *ptr),
18-
| ^^^^^^^^^^^^^^^^^^
19-
help: <TAG> is protected for the duration of this call
14+
help: <TAG> cannot be used for memory access because that would remove protected tag <TAG>, protected by this function call
2015
--> $DIR/newtype_retagging.rs:LL:CC
2116
|
2217
LL | / fn dealloc_while_running(_n: Newtype<'_>, dealloc: impl FnOnce()) {
2318
LL | | dealloc();
2419
LL | | }
2520
| |_^
21+
help: <TAG> was derived from <TAG>, which in turn was created here
22+
--> $DIR/newtype_retagging.rs:LL:CC
23+
|
24+
LL | Newtype(&mut *ptr),
25+
| ^^^^^^^^^^^^^^^^^^
2626
= note: backtrace:
2727
= note: inside `std::boxed::Box::<i32>::from_raw_in` at RUSTLIB/alloc/src/boxed.rs:LL:CC
2828
= note: inside `std::boxed::Box::<i32>::from_raw` at RUSTLIB/alloc/src/boxed.rs:LL:CC

0 commit comments

Comments
 (0)