about summary refs log tree commit diff
path: root/tests/ui/lint/int_to_ptr-unsized.rs
blob: bbdc2474561c0cf69d2d4b5fa3cf0fb4f31eb650 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Checks for the `integer_to_pointer_transmutes` lint with unsized types
//
// Related to https://github.com/rust-lang/rust/issues/145935

//@ check-pass

#![allow(non_camel_case_types)]
#![allow(unused_unsafe)]

#[cfg(target_pointer_width = "64")]
type usizemetadata = i128;

#[cfg(target_pointer_width = "32")]
type usizemetadata = i64;

unsafe fn unsized_type(a: usize) {
    let _ref = unsafe { std::mem::transmute::<usizemetadata, &'static str>(0xff) };
    //~^ WARN transmuting an integer to a pointer
    let _ptr = unsafe { std::mem::transmute::<usizemetadata, *const [u8]>(0xff) };
    //~^ WARN transmuting an integer to a pointer
}

fn main() {}