test that we cannot access unescaped static memory with a raw ptr
This commit is contained in:
parent
e03255d625
commit
9f48b3029c
7
tests/compile-fail/stacked_borrows/unescaped_static.rs
Normal file
7
tests/compile-fail/stacked_borrows/unescaped_static.rs
Normal file
@ -0,0 +1,7 @@
|
||||
static ARRAY: [u8; 2] = [0, 1];
|
||||
|
||||
fn main() {
|
||||
let ptr_to_first = &ARRAY[0] as *const u8;
|
||||
// Illegally use this to access the 2nd element.
|
||||
let _val = unsafe { *ptr_to_first.add(1) }; //~ ERROR borrow stack
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user