Skip to content

Commit f850318

Browse files
committed
Auto merge of #2746 - RalfJung:retag-diagnostic, r=RalfJung
tweaks to retag diagnostic handling Salvaged from rust-lang/rust#106212
2 parents 61a933f + dc2f522 commit f850318

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ impl fmt::Display for InvalidationCause {
8888
match self {
8989
InvalidationCause::Access(kind) => write!(f, "{kind}"),
9090
InvalidationCause::Retag(perm, kind) =>
91-
if *kind == RetagCause::FnEntry {
92-
write!(f, "{perm:?} FnEntry retag")
93-
} else {
94-
write!(f, "{perm:?} retag")
95-
},
91+
write!(f, "{perm:?} {retag}", retag = kind.summary()),
9692
}
9793
}
9894
}
@@ -193,7 +189,7 @@ struct RetagOp {
193189
#[derive(Debug, Clone, Copy, PartialEq)]
194190
pub enum RetagCause {
195191
Normal,
196-
FnReturn,
192+
FnReturnPlace,
197193
FnEntry,
198194
TwoPhase,
199195
}
@@ -495,8 +491,8 @@ impl RetagCause {
495491
fn summary(&self) -> String {
496492
match self {
497493
RetagCause::Normal => "retag",
498-
RetagCause::FnEntry => "FnEntry retag",
499-
RetagCause::FnReturn => "FnReturn retag",
494+
RetagCause::FnEntry => "function-entry retag",
495+
RetagCause::FnReturnPlace => "return-place retag",
500496
RetagCause::TwoPhase => "two-phase retag",
501497
}
502498
.to_string()

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
998998
access: Some(AccessKind::Write),
999999
protector: Some(ProtectorKind::StrongProtector),
10001000
};
1001-
let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturn)?;
1001+
let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturnPlace)?;
10021002
// And use reborrowed pointer for return place.
10031003
let return_place = this.ref_to_mplace(&val)?;
10041004
this.frame_mut().return_place = return_place.into();

tests/fail/stacked_borrows/aliasing_mut3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | pub fn safe(_x: &mut i32, _y: &i32) {}
55
| ^^
66
| |
77
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of FnEntry retag at ALLOC[0x0..0x4]
8+
| this error occurs as part of function-entry retag at ALLOC[0x0..0x4]
99
|
1010
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
@@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0x4]
1414
|
1515
LL | safe_raw(xraw, xshr);
1616
| ^^^^
17-
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call
17+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call
1818
--> $DIR/aliasing_mut3.rs:LL:CC
1919
|
2020
LL | safe_raw(xraw, xshr);

tests/fail/stacked_borrows/fnentry_invalidation.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1414
|
1515
LL | let z = &mut x as *mut i32;
1616
| ^^^^^^
17-
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call
17+
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call
1818
--> $DIR/fnentry_invalidation.rs:LL:CC
1919
|
2020
LL | x.do_bad();

tests/fail/stacked_borrows/fnentry_invalidation2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0xc]
1414
|
1515
LL | let ptr = t.sli.as_ptr();
1616
| ^^^^^^^^^^^^^^
17-
help: <TAG> was later invalidated at offsets [0x0..0xc] by a Unique FnEntry retag inside this call
17+
help: <TAG> was later invalidated at offsets [0x0..0xc] by a Unique function-entry retag inside this call
1818
--> $DIR/fnentry_invalidation2.rs:LL:CC
1919
|
2020
LL | let _ = t.sli.as_mut_ptr();

0 commit comments

Comments
 (0)