parent
28969f47aa
commit
4a03e45169
2 changed files with 26 additions and 0 deletions
13
tests/compile-fail/transmute_fat.rs
Normal file
13
tests/compile-fail/transmute_fat.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![feature(i128_type)]
|
||||
|
||||
fn main() {
|
||||
#[cfg(target_pointer_width="64")]
|
||||
let bad = unsafe {
|
||||
std::mem::transmute::<&[u8], u128>(&[1u8])
|
||||
};
|
||||
#[cfg(target_pointer_width="32")]
|
||||
let bad = unsafe {
|
||||
std::mem::transmute::<&[u8], u64>(&[1u8])
|
||||
};
|
||||
bad + 1; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
13
tests/compile-fail/transmute_fat2.rs
Normal file
13
tests/compile-fail/transmute_fat2.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![feature(i128_type)]
|
||||
|
||||
fn main() {
|
||||
#[cfg(target_pointer_width="64")]
|
||||
let bad = unsafe {
|
||||
std::mem::transmute::<u128, &[u8]>(42)
|
||||
};
|
||||
#[cfg(target_pointer_width="32")]
|
||||
let bad = unsafe {
|
||||
std::mem::transmute::<u64, &[u8]>(42)
|
||||
};
|
||||
bad[0]; //~ ERROR index out of bounds: the len is 0 but the index is 0
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue