]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
064997fb 1#![warn(clippy::transmute_ptr_to_ref)]
fe692bf9 2#![allow(clippy::match_single_binding, clippy::unnecessary_cast)]
064997fb
FG
3
4unsafe 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
27fn _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
42unsafe 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
487cf647 51#[clippy::msrv = "1.38"]
064997fb 52unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
064997fb
FG
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
487cf647 63#[clippy::msrv = "1.37"]
064997fb 64unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
064997fb
FG
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
75fn main() {}