]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/cast_alignment.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / cast_alignment.rs
CommitLineData
f20569fa
XL
1//! Test casts for alignment issues
2
3#![feature(rustc_private)]
4extern crate libc;
5
6#[warn(clippy::cast_ptr_alignment)]
7#[allow(clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
8fn main() {
9 /* These should be warned against */
10
11 // cast to more-strictly-aligned type
12 (&1u8 as *const u8) as *const u16;
13 (&mut 1u8 as *mut u8) as *mut u16;
14
15 // cast to more-strictly-aligned type, but with the `pointer::cast` function.
16 (&1u8 as *const u8).cast::<u16>();
17 (&mut 1u8 as *mut u8).cast::<u16>();
18
19 /* These should be ok */
20
21 // not a pointer type
22 1u8 as u16;
23 // cast to less-strictly-aligned type
24 (&1u16 as *const u16) as *const u8;
25 (&mut 1u16 as *mut u16) as *mut u8;
26 // For c_void, we should trust the user. See #2677
27 (&1u32 as *const u32 as *const std::os::raw::c_void) as *const u32;
28 (&1u32 as *const u32 as *const libc::c_void) as *const u32;
29 // For ZST, we should trust the user. See #4256
30 (&1u32 as *const u32 as *const ()) as *const u32;
31}