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