fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1//@aux-build:proc_macros.rs 2 3#![warn(clippy::ptr_as_ptr)] 4 5#[macro_use] 6extern crate proc_macros; 7 8mod issue_11278_a { 9 #[derive(Debug)] 10 pub struct T<D: std::fmt::Debug + ?Sized> { 11 pub p: D, 12 } 13} 14 15mod issue_11278_b { 16 pub fn f(o: &mut super::issue_11278_a::T<dyn std::fmt::Debug>) -> super::issue_11278_a::T<String> { 17 // Retain `super` 18 *unsafe { Box::from_raw(Box::into_raw(Box::new(o)).cast::<super::issue_11278_a::T<String>>()) } 19 } 20} 21 22#[inline_macros] 23fn main() { 24 let ptr: *const u32 = &42_u32; 25 let mut_ptr: *mut u32 = &mut 42_u32; 26 27 let _ = ptr.cast::<i32>(); 28 let _ = mut_ptr.cast::<i32>(); 29 30 // Make sure the lint can handle the difference in their operator precedences. 31 unsafe { 32 let ptr_ptr: *const *const u32 = &ptr; 33 let _ = (*ptr_ptr).cast::<i32>(); 34 } 35 36 // Changes in mutability. Do not lint this. 37 let _ = ptr as *mut i32; 38 let _ = mut_ptr as *const i32; 39 40 // `pointer::cast` cannot perform unsized coercions unlike `as`. Do not lint this. 41 let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4]; 42 let _ = ptr_of_array as *const [u32]; 43 let _ = ptr_of_array as *const dyn std::fmt::Debug; 44 45 // Ensure the lint doesn't produce unnecessary turbofish for inferred types. 46 let _: *const i32 = ptr.cast(); 47 let _: *mut i32 = mut_ptr.cast(); 48 49 // Make sure the lint is triggered inside a macro 50 let _ = inline!($ptr.cast::<i32>()); 51 52 // Do not lint inside macros from external crates 53 let _ = external!($ptr as *const i32); 54} 55 56#[clippy::msrv = "1.37"] 57fn _msrv_1_37() { 58 let ptr: *const u32 = &42_u32; 59 let mut_ptr: *mut u32 = &mut 42_u32; 60 61 // `pointer::cast` was stabilized in 1.38. Do not lint this 62 let _ = ptr as *const i32; 63 let _ = mut_ptr as *mut i32; 64} 65 66#[clippy::msrv = "1.38"] 67fn _msrv_1_38() { 68 let ptr: *const u32 = &42_u32; 69 let mut_ptr: *mut u32 = &mut 42_u32; 70 71 let _ = ptr.cast::<i32>(); 72 let _ = mut_ptr.cast::<i32>(); 73}