1 //! Test casts for alignment issues
3 #![feature(rustc_private)]
6 #[warn(clippy::cast_ptr_alignment)]
9 clippy::unnecessary_operation,
10 clippy::cast_lossless,
15 /* These should be warned against */
17 // cast to more-strictly-aligned type
18 (&1u8 as *const u8) as *const u16;
19 (&mut 1u8 as *mut u8) as *mut u16;
21 // cast to more-strictly-aligned type, but with the `pointer::cast` function.
22 (&1u8 as *const u8).cast::<u16>();
23 (&mut 1u8 as *mut u8).cast::<u16>();
25 /* These should be ok */
29 // cast to less-strictly-aligned type
30 (&1u16 as *const u16) as *const u8;
31 (&mut 1u16 as *mut u16) as *mut u8;
32 // For c_void, we should trust the user. See #2677
33 (&1u32 as *const u32 as *const std::os::raw::c_void) as *const u32;
34 (&1u32 as *const u32 as *const libc::c_void) as *const u32;
35 // For ZST, we should trust the user. See #4256
36 (&1u32 as *const u32 as *const ()) as *const u32;