Skip to content

Commit e362c30

Browse files
authored
Merge pull request rust-lang#242 from solson/various
Add tests for rust-lang#113
2 parents 28969f4 + 4a03e45 commit e362c30

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/compile-fail/transmute_fat.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(i128_type)]
2+
3+
fn main() {
4+
#[cfg(target_pointer_width="64")]
5+
let bad = unsafe {
6+
std::mem::transmute::<&[u8], u128>(&[1u8])
7+
};
8+
#[cfg(target_pointer_width="32")]
9+
let bad = unsafe {
10+
std::mem::transmute::<&[u8], u64>(&[1u8])
11+
};
12+
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

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(i128_type)]
2+
3+
fn main() {
4+
#[cfg(target_pointer_width="64")]
5+
let bad = unsafe {
6+
std::mem::transmute::<u128, &[u8]>(42)
7+
};
8+
#[cfg(target_pointer_width="32")]
9+
let bad = unsafe {
10+
std::mem::transmute::<u64, &[u8]>(42)
11+
};
12+
bad[0]; //~ ERROR index out of bounds: the len is 0 but the index is 0
13+
}

0 commit comments

Comments
 (0)