]> git.lizzy.rs Git - rust.git/blob - tests/ui/cast_alignment.rs
Don't lint `if_same_then_else` with `if let` conditions
[rust.git] / tests / ui / cast_alignment.rs
1 //! Test casts for alignment issues
2
3 #![feature(rustc_private)]
4 extern crate libc;
5
6 #[warn(clippy::cast_ptr_alignment)]
7 #[allow(
8     clippy::no_effect,
9     clippy::unnecessary_operation,
10     clippy::cast_lossless,
11     clippy::borrow_as_ptr
12 )]
13
14 fn main() {
15     /* These should be warned against */
16
17     // cast to more-strictly-aligned type
18     (&1u8 as *const u8) as *const u16;
19     (&mut 1u8 as *mut u8) as *mut u16;
20
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>();
24
25     /* These should be ok */
26
27     // not a pointer type
28     1u8 as u16;
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;
37 }