2023-04-20 14:37:15 +00:00
|
|
|
//@run-rustfix
|
2022-06-04 02:12:26 +00:00
|
|
|
|
|
|
|
#![warn(clippy::transmute_ptr_to_ref)]
|
|
|
|
#![allow(clippy::match_single_binding)]
|
|
|
|
|
|
|
|
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
|
|
|
|
let _: &T = &*p;
|
|
|
|
let _: &T = &*p;
|
|
|
|
|
|
|
|
let _: &mut T = &mut *m;
|
|
|
|
let _: &mut T = &mut *m;
|
|
|
|
|
|
|
|
let _: &T = &*m;
|
|
|
|
let _: &T = &*m;
|
|
|
|
|
|
|
|
let _: &mut T = &mut *(p as *mut T);
|
|
|
|
let _ = &mut *(p as *mut T);
|
|
|
|
|
|
|
|
let _: &T = &*(o as *const T);
|
|
|
|
let _: &T = &*(o as *const T);
|
|
|
|
|
|
|
|
let _: &mut T = &mut *(om as *mut T);
|
|
|
|
let _: &mut T = &mut *(om as *mut T);
|
|
|
|
|
|
|
|
let _: &T = &*(om as *const T);
|
|
|
|
let _: &T = &*(om as *const T);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn _issue1231() {
|
|
|
|
struct Foo<'a, T> {
|
|
|
|
bar: &'a T,
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = 42 as *const i32;
|
|
|
|
let _: &Foo<u8> = unsafe { &*raw.cast::<Foo<_>>() };
|
|
|
|
|
|
|
|
let _: &Foo<&u8> = unsafe { &*raw.cast::<Foo<&_>>() };
|
|
|
|
|
|
|
|
type Bar<'a> = &'a u8;
|
|
|
|
let raw = 42 as *const i32;
|
|
|
|
unsafe { &*(raw as *const u8) };
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 {
|
|
|
|
match 0 {
|
|
|
|
0 => &*x.cast::<&u32>(),
|
|
|
|
1 => &*y.cast::<&u32>(),
|
|
|
|
2 => &*x.cast::<&'b u32>(),
|
|
|
|
_ => &*y.cast::<&'b u32>(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:50:02 +00:00
|
|
|
#[clippy::msrv = "1.38"]
|
2022-06-04 02:12:26 +00:00
|
|
|
unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
|
|
|
|
let a = 0u32;
|
|
|
|
let a = &a as *const u32;
|
|
|
|
let _: &u32 = &*a;
|
|
|
|
let _: &u32 = &*a.cast::<u32>();
|
|
|
|
match 0 {
|
|
|
|
0 => &*x.cast::<&u32>(),
|
|
|
|
_ => &*x.cast::<&'b u32>(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:50:02 +00:00
|
|
|
#[clippy::msrv = "1.37"]
|
2022-06-04 02:12:26 +00:00
|
|
|
unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
|
|
|
|
let a = 0u32;
|
|
|
|
let a = &a as *const u32;
|
|
|
|
let _: &u32 = &*a;
|
|
|
|
let _: &u32 = &*(a as *const u32);
|
|
|
|
match 0 {
|
|
|
|
0 => &*(x as *const () as *const &u32),
|
|
|
|
_ => &*(x as *const () as *const &'b u32),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|