Skip to content

Commit 6dacaf0

Browse files
committed
tweak Box retag diagnostics
1 parent a00de3d commit 6dacaf0

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ impl fmt::Display for InvalidationCause {
8686
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8787
match self {
8888
InvalidationCause::Access(kind) => write!(f, "{kind}"),
89-
InvalidationCause::Retag(perm, kind) =>
90-
if *kind == RetagCause::FnEntry {
91-
write!(f, "{perm:?} FnEntry retag")
92-
} else {
93-
write!(f, "{perm:?} retag")
94-
},
89+
InvalidationCause::Retag(perm, kind) => write!(f, "{perm:?} {retag}", retag = kind.summary()),
9590
}
9691
}
9792
}
@@ -192,6 +187,7 @@ struct RetagOp {
192187
#[derive(Debug, Clone, Copy, PartialEq)]
193188
pub enum RetagCause {
194189
Normal,
190+
Box,
195191
FnReturnPlace,
196192
FnEntry,
197193
TwoPhase,
@@ -490,6 +486,7 @@ impl RetagCause {
490486
fn summary(&self) -> String {
491487
match self {
492488
RetagCause::Normal => "retag",
489+
RetagCause::Box => "Box retag",
493490
RetagCause::FnEntry => "FnEntry retag",
494491
RetagCause::FnReturnPlace => "return-place retag",
495492
RetagCause::TwoPhase => "two-phase retag",

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl<'tcx> Stack {
221221
if !global.tracked_pointer_tags.is_empty() {
222222
dcx.check_tracked_tag_popped(item, global);
223223
}
224+
dcx.log_invalidation(item.tag());
224225

225226
if !item.protected() {
226227
return Ok(());
@@ -281,7 +282,6 @@ impl<'tcx> Stack {
281282
};
282283
self.pop_items_after(first_incompatible_idx, |item| {
283284
Stack::item_invalidated(&item, global, dcx)?;
284-
dcx.log_invalidation(item.tag());
285285
Ok(())
286286
})?;
287287
} else {
@@ -302,7 +302,6 @@ impl<'tcx> Stack {
302302
};
303303
self.disable_uniques_starting_at(first_incompatible_idx, |item| {
304304
Stack::item_invalidated(&item, global, dcx)?;
305-
dcx.log_invalidation(item.tag());
306305
Ok(())
307306
})?;
308307
}
@@ -928,7 +927,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
928927
access: Some(AccessKind::Write),
929928
protector: false,
930929
};
931-
self.retag_ptr_inplace(place, new_perm, self.retag_cause)
930+
self.retag_ptr_inplace(place, new_perm, RetagCause::Box)
932931
}
933932

934933
fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {

src/tools/miri/tests/fail/stacked_borrows/box_noalias_violation.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0x4]
1414
|
1515
LL | let ptr = &*b as *const i32;
1616
| ^^^
17-
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique retag
17+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique Box retag
1818
--> $DIR/box_noalias_violation.rs:LL:CC
1919
|
2020
LL | test(b, ptr);

src/tools/miri/tests/fail/stacked_borrows/return-noalias.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ help: <TAG> was created here, as the base tag for ALLOC
1414
|
1515
LL | let b = unsafe { Box::from_raw(&mut m) };
1616
| ^^^^^^
17+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique Box retag
18+
--> $DIR/return-noalias.rs:LL:CC
19+
|
20+
LL | let b = unsafe { Box::from_raw(&mut m) };
21+
| ^^^^^^^^^^^^^^^^^^^^^
1722
= note: BACKTRACE (of the first span):
1823
= note: inside `main` at $DIR/return-noalias.rs:LL:CC
1924
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)