]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / transmute_ptr_to_ref.fixed
1 #![warn(clippy::transmute_ptr_to_ref)]
2 #![allow(clippy::match_single_binding, clippy::unnecessary_cast)]
3
4 unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
5 let _: &T = &*p;
6 let _: &T = &*p;
7
8 let _: &mut T = &mut *m;
9 let _: &mut T = &mut *m;
10
11 let _: &T = &*m;
12 let _: &T = &*m;
13
14 let _: &mut T = &mut *(p as *mut T);
15 let _ = &mut *(p as *mut T);
16
17 let _: &T = &*(o as *const T);
18 let _: &T = &*(o as *const T);
19
20 let _: &mut T = &mut *(om as *mut T);
21 let _: &mut T = &mut *(om as *mut T);
22
23 let _: &T = &*(om as *const T);
24 let _: &T = &*(om as *const T);
25 }
26
27 fn _issue1231() {
28 struct Foo<'a, T> {
29 bar: &'a T,
30 }
31
32 let raw = 42 as *const i32;
33 let _: &Foo<u8> = unsafe { &*raw.cast::<Foo<_>>() };
34
35 let _: &Foo<&u8> = unsafe { &*raw.cast::<Foo<&_>>() };
36
37 type Bar<'a> = &'a u8;
38 let raw = 42 as *const i32;
39 unsafe { &*(raw as *const u8) };
40 }
41
42 unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 {
43 match 0 {
44 0 => &*x.cast::<&u32>(),
45 1 => &*y.cast::<&u32>(),
46 2 => &*x.cast::<&'b u32>(),
47 _ => &*y.cast::<&'b u32>(),
48 }
49 }
50
51 #[clippy::msrv = "1.38"]
52 unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
53 let a = 0u32;
54 let a = &a as *const u32;
55 let _: &u32 = &*a;
56 let _: &u32 = &*a.cast::<u32>();
57 match 0 {
58 0 => &*x.cast::<&u32>(),
59 _ => &*x.cast::<&'b u32>(),
60 }
61 }
62
63 #[clippy::msrv = "1.37"]
64 unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
65 let a = 0u32;
66 let a = &a as *const u32;
67 let _: &u32 = &*a;
68 let _: &u32 = &*(a as *const u32);
69 match 0 {
70 0 => &*(x as *const () as *const &u32),
71 _ => &*(x as *const () as *const &'b u32),
72 }
73 }
74
75 fn main() {}