]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/ptr_as_ptr.fixed
Rollup merge of #84221 - ABouttefeux:generic-arg-elision, r=estebank
[rust.git] / src / tools / clippy / tests / ui / ptr_as_ptr.fixed
1 // run-rustfix
2
3 #![warn(clippy::ptr_as_ptr)]
4 #![feature(custom_inner_attributes)]
5
6 fn main() {
7     let ptr: *const u32 = &42_u32;
8     let mut_ptr: *mut u32 = &mut 42_u32;
9
10     let _ = ptr.cast::<i32>();
11     let _ = mut_ptr.cast::<i32>();
12
13     // Make sure the lint can handle the difference in their operator precedences.
14     unsafe {
15         let ptr_ptr: *const *const u32 = &ptr;
16         let _ = (*ptr_ptr).cast::<i32>();
17     }
18
19     // Changes in mutability. Do not lint this.
20     let _ = ptr as *mut i32;
21     let _ = mut_ptr as *const i32;
22
23     // `pointer::cast` cannot perform unsized coercions unlike `as`. Do not lint this.
24     let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4];
25     let _ = ptr_of_array as *const [u32];
26     let _ = ptr_of_array as *const dyn std::fmt::Debug;
27
28     // Ensure the lint doesn't produce unnecessary turbofish for inferred types.
29     let _: *const i32 = ptr.cast();
30     let _: *mut i32 = mut_ptr.cast();
31 }
32
33 fn _msrv_1_37() {
34     #![clippy::msrv = "1.37"]
35     let ptr: *const u32 = &42_u32;
36     let mut_ptr: *mut u32 = &mut 42_u32;
37
38     // `pointer::cast` was stabilized in 1.38. Do not lint this
39     let _ = ptr as *const i32;
40     let _ = mut_ptr as *mut i32;
41 }
42
43 fn _msrv_1_38() {
44     #![clippy::msrv = "1.38"]
45     let ptr: *const u32 = &42_u32;
46     let mut_ptr: *mut u32 = &mut 42_u32;
47
48     let _ = ptr.cast::<i32>();
49     let _ = mut_ptr.cast::<i32>();
50 }