We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5a801c0 commit ba8eb76Copy full SHA for ba8eb76
tests/compile-fail/stacked_borrows/mut_exclusive_violation1.rs
@@ -0,0 +1,29 @@
1
+fn demo_mut_advanced_unique(our: &mut i32) -> i32 {
2
+ unknown_code_1(&*our);
3
+
4
+ // This "re-asserts" uniqueness of the reference: After writing, we know
5
+ // our tag is at the top of the stack.
6
+ *our = 5;
7
8
+ unknown_code_2();
9
10
+ // We know this will return 5
11
+ *our
12
+}
13
14
+// Now comes the evil context
15
+use std::ptr;
16
17
+static mut LEAK: *mut i32 = ptr::null_mut();
18
19
+fn unknown_code_1(x: &i32) { unsafe {
20
+ LEAK = x as *const _ as *mut _;
21
+} }
22
23
+fn unknown_code_2() { unsafe {
24
+ *LEAK = 7; //~ ERROR does not exist on the stack
25
26
27
+fn main() {
28
+ assert_eq!(demo_mut_advanced_unique(&mut 0), 5);
29
0 commit comments