File tree 2 files changed +15
-13
lines changed
2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,15 @@ impl Foo {
16
16
17
17
pub fn main ( ) {
18
18
let mut f = Foo ( 0 ) ;
19
- let inner = & mut f. 0 as * mut u64 ;
20
- let _res = f. add ( unsafe {
21
- let n = f. 0 ;
19
+ let alias = & mut f. 0 as * mut u64 ;
20
+ let res = f. add ( unsafe {
22
21
// This is the access at fault, but it's not immediately apparent because
23
22
// the reference that got invalidated is not under a Protector.
24
- * inner = 42 ;
25
- n
23
+ * alias = 42 ;
24
+ 0
26
25
} ) ;
26
+ // `res` could be optimized to be `0`, since at the time the reference for the `self` argument
27
+ // is created, it has value `0`, and then later we add `0` to that. But turns out there is
28
+ // a sneaky alias that's used to change the value of `*self` before it is read...
29
+ assert_eq ! ( res, 42 ) ;
27
30
}
Original file line number Diff line number Diff line change @@ -9,26 +9,25 @@ LL | fn add(&mut self, n: u64) -> u64 {
9
9
help: the accessed tag <TAG> was created here, in the initial state Reserved
10
10
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
11
11
|
12
- LL | let _res = f.add(unsafe {
13
- | ^
12
+ LL | let res = f.add(unsafe {
13
+ | ^
14
14
help: the accessed tag <TAG> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x8]
15
15
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
16
16
|
17
- LL | *inner = 42;
17
+ LL | *alias = 42;
18
18
| ^^^^^^^^^^^
19
19
= help: this transition corresponds to a loss of read and write permissions
20
20
= note: BACKTRACE (of the first span):
21
21
= note: inside `Foo::add` at tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
22
22
note: inside `main`
23
23
--> tests/fail/tree_borrows/write-during-2phase.rs:LL:CC
24
24
|
25
- LL | let _res = f.add(unsafe {
26
- | ________________^
27
- LL | | let n = f.0;
25
+ LL | let res = f.add(unsafe {
26
+ | _______________^
28
27
LL | | // This is the access at fault, but it's not immediately apparent because
29
28
LL | | // the reference that got invalidated is not under a Protector.
30
- LL | | *inner = 42;
31
- LL | | n
29
+ LL | | *alias = 42;
30
+ LL | | 0
32
31
LL | | });
33
32
| |______^
34
33
You can’t perform that action at this time.
0 commit comments