Make sure that casting a ptr-integer down to u8 makes it unusable
This commit is contained in:
parent
86e2367029
commit
7b7f690274
1 changed files with 7 additions and 0 deletions
7
tests/compile-fail/ptr_int_cast.rs
Normal file
7
tests/compile-fail/ptr_int_cast.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
let x = &1;
|
||||
// Casting down to u8 and back up to a pointer loses too much precision; this must not work.
|
||||
let x = x as *const i32 as u8;
|
||||
let x = x as *const i32; //~ ERROR: a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let _ = unsafe { *x };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue