simplify Tree Borrows write-during-2phase example
This commit is contained in:
parent
256d63f444
commit
ccdea3ee36
@ -16,12 +16,15 @@ fn add(&mut self, n: u64) -> u64 { //~ ERROR: /reborrow through .* is forbidden/
|
||||
|
||||
pub fn main() {
|
||||
let mut f = Foo(0);
|
||||
let inner = &mut f.0 as *mut u64;
|
||||
let _res = f.add(unsafe {
|
||||
let n = f.0;
|
||||
let alias = &mut f.0 as *mut u64;
|
||||
let res = f.add(unsafe {
|
||||
// This is the access at fault, but it's not immediately apparent because
|
||||
// the reference that got invalidated is not under a Protector.
|
||||
*inner = 42;
|
||||
n
|
||||
*alias = 42;
|
||||
0
|
||||
});
|
||||
// `res` could be optimized to be `0`, since at the time the reference for the `self` argument
|
||||
// is created, it has value `0`, and then later we add `0` to that. But turns out there is
|
||||
// a sneaky alias that's used to change the value of `*self` before it is read...
|
||||
assert_eq!(res, 42);
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ LL | fn add(&mut self, n: u64) -> u64 {
|
||||
help: the accessed tag <TAG> was created here, in the initial state Reserved
|
||||
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
|
||||
|
|
||||
LL | let _res = f.add(unsafe {
|
||||
| ^
|
||||
LL | let res = f.add(unsafe {
|
||||
| ^
|
||||
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x8]
|
||||
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
|
||||
|
|
||||
LL | *inner = 42;
|
||||
LL | *alias = 42;
|
||||
| ^^^^^^^^^^^
|
||||
= help: this transition corresponds to a loss of read and write permissions
|
||||
= note: BACKTRACE (of the first span):
|
||||
@ -22,13 +22,12 @@ LL | *inner = 42;
|
||||
note: inside `main`
|
||||
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
|
||||
|
|
||||
LL | let _res = f.add(unsafe {
|
||||
| ________________^
|
||||
LL | | let n = f.0;
|
||||
LL | let res = f.add(unsafe {
|
||||
| _______________^
|
||||
LL | | // This is the access at fault, but it's not immediately apparent because
|
||||
LL | | // the reference that got invalidated is not under a Protector.
|
||||
LL | | *inner = 42;
|
||||
LL | | n
|
||||
LL | | *alias = 42;
|
||||
LL | | 0
|
||||
LL | | });
|
||||
| |______^
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user