Skip to content

tweaks to retag diagnostic handling #2746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/borrow_tracker/stacked_borrows/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ impl fmt::Display for InvalidationCause {
match self {
InvalidationCause::Access(kind) => write!(f, "{kind}"),
InvalidationCause::Retag(perm, kind) =>
if *kind == RetagCause::FnEntry {
write!(f, "{perm:?} FnEntry retag")
} else {
write!(f, "{perm:?} retag")
},
write!(f, "{perm:?} {retag}", retag = kind.summary()),
}
}
}
Expand Down Expand Up @@ -193,7 +189,7 @@ struct RetagOp {
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RetagCause {
Normal,
FnReturn,
FnReturnPlace,
FnEntry,
TwoPhase,
}
Expand Down Expand Up @@ -495,8 +491,8 @@ impl RetagCause {
fn summary(&self) -> String {
match self {
RetagCause::Normal => "retag",
RetagCause::FnEntry => "FnEntry retag",
RetagCause::FnReturn => "FnReturn retag",
RetagCause::FnEntry => "function-entry retag",
RetagCause::FnReturnPlace => "return-place retag",
RetagCause::TwoPhase => "two-phase retag",
}
.to_string()
Expand Down
2 changes: 1 addition & 1 deletion src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
access: Some(AccessKind::Write),
protector: Some(ProtectorKind::StrongProtector),
};
let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturn)?;
let val = this.sb_retag_reference(&val, new_perm, RetagCause::FnReturnPlace)?;
// And use reborrowed pointer for return place.
let return_place = this.ref_to_mplace(&val)?;
this.frame_mut().return_place = return_place.into();
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/stacked_borrows/aliasing_mut3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub fn safe(_x: &mut i32, _y: &i32) {}
| ^^
| |
| trying to retag from <TAG> 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]
| this error occurs as part of function-entry 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
Expand All @@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0x4]
|
LL | safe_raw(xraw, xshr);
| ^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call
--> $DIR/aliasing_mut3.rs:LL:CC
|
LL | safe_raw(xraw, xshr);
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/stacked_borrows/fnentry_invalidation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
|
LL | let z = &mut x as *mut i32;
| ^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique FnEntry retag inside this call
help: <TAG> was later invalidated at offsets [0x0..0x4] by a Unique function-entry retag inside this call
--> $DIR/fnentry_invalidation.rs:LL:CC
|
LL | x.do_bad();
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/stacked_borrows/fnentry_invalidation2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ help: <TAG> was created by a SharedReadOnly retag at offsets [0x0..0xc]
|
LL | let ptr = t.sli.as_ptr();
| ^^^^^^^^^^^^^^
help: <TAG> was later invalidated at offsets [0x0..0xc] by a Unique FnEntry retag inside this call
help: <TAG> was later invalidated at offsets [0x0..0xc] by a Unique function-entry retag inside this call
--> $DIR/fnentry_invalidation2.rs:LL:CC
|
LL | let _ = t.sli.as_mut_ptr();
Expand Down