2 // aux-build:macro_rules.rs
4 #![warn(clippy::ptr_as_ptr)]
5 #![feature(custom_inner_attributes)]
7 extern crate macro_rules;
16 let ptr: *const u32 = &42_u32;
17 let mut_ptr: *mut u32 = &mut 42_u32;
19 let _ = ptr as *const i32;
20 let _ = mut_ptr as *mut i32;
22 // Make sure the lint can handle the difference in their operator precedences.
24 let ptr_ptr: *const *const u32 = &ptr;
25 let _ = *ptr_ptr as *const i32;
28 // Changes in mutability. Do not lint this.
29 let _ = ptr as *mut i32;
30 let _ = mut_ptr as *const i32;
32 // `pointer::cast` cannot perform unsized coercions unlike `as`. Do not lint this.
33 let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4];
34 let _ = ptr_of_array as *const [u32];
35 let _ = ptr_of_array as *const dyn std::fmt::Debug;
37 // Ensure the lint doesn't produce unnecessary turbofish for inferred types.
38 let _: *const i32 = ptr as *const _;
39 let _: *mut i32 = mut_ptr as _;
41 // Make sure the lint is triggered inside a macro
42 let _ = cast_it!(ptr);
44 // Do not lint inside macros from external crates
45 let _ = macro_rules::ptr_as_ptr_cast!(ptr);
49 #![clippy::msrv = "1.37"]
50 let ptr: *const u32 = &42_u32;
51 let mut_ptr: *mut u32 = &mut 42_u32;
53 // `pointer::cast` was stabilized in 1.38. Do not lint this
54 let _ = ptr as *const i32;
55 let _ = mut_ptr as *mut i32;
59 #![clippy::msrv = "1.38"]
60 let ptr: *const u32 = &42_u32;
61 let mut_ptr: *mut u32 = &mut 42_u32;
63 let _ = ptr as *const i32;
64 let _ = mut_ptr as *mut i32;