2022-06-03 21:12:26 -05:00
|
|
|
// run-rustfix
|
|
|
|
|
2020-01-19 20:16:50 -06:00
|
|
|
#![warn(clippy::transmute_ptr_to_ref)]
|
2022-06-03 21:12:26 -05:00
|
|
|
#![allow(clippy::match_single_binding)]
|
2020-01-19 20:16:50 -06:00
|
|
|
|
|
|
|
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
|
|
|
|
let _: &T = std::mem::transmute(p);
|
|
|
|
let _: &T = &*p;
|
|
|
|
|
|
|
|
let _: &mut T = std::mem::transmute(m);
|
|
|
|
let _: &mut T = &mut *m;
|
|
|
|
|
|
|
|
let _: &T = std::mem::transmute(m);
|
|
|
|
let _: &T = &*m;
|
|
|
|
|
|
|
|
let _: &mut T = std::mem::transmute(p as *mut T);
|
|
|
|
let _ = &mut *(p as *mut T);
|
|
|
|
|
|
|
|
let _: &T = std::mem::transmute(o);
|
|
|
|
let _: &T = &*(o as *const T);
|
|
|
|
|
|
|
|
let _: &mut T = std::mem::transmute(om);
|
|
|
|
let _: &mut T = &mut *(om as *mut T);
|
|
|
|
|
|
|
|
let _: &T = std::mem::transmute(om);
|
|
|
|
let _: &T = &*(om as *const T);
|
|
|
|
}
|
|
|
|
|
2022-06-03 21:12:26 -05:00
|
|
|
fn _issue1231() {
|
2020-01-19 20:16:50 -06:00
|
|
|
struct Foo<'a, T> {
|
|
|
|
bar: &'a T,
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = 42 as *const i32;
|
|
|
|
let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
|
|
|
|
|
|
|
|
let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };
|
|
|
|
|
|
|
|
type Bar<'a> = &'a u8;
|
|
|
|
let raw = 42 as *const i32;
|
|
|
|
unsafe { std::mem::transmute::<_, Bar>(raw) };
|
|
|
|
}
|
|
|
|
|
2022-06-03 21:12:26 -05:00
|
|
|
unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 {
|
|
|
|
match 0 {
|
|
|
|
0 => std::mem::transmute(x),
|
|
|
|
1 => std::mem::transmute(y),
|
|
|
|
2 => std::mem::transmute::<_, &&'b u32>(x),
|
|
|
|
_ => std::mem::transmute::<_, &&'b u32>(y),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.38"]
|
2022-06-03 21:12:26 -05: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 = std::mem::transmute(a);
|
|
|
|
let _: &u32 = std::mem::transmute::<_, &u32>(a);
|
|
|
|
match 0 {
|
|
|
|
0 => std::mem::transmute(x),
|
|
|
|
_ => std::mem::transmute::<_, &&'b u32>(x),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.37"]
|
2022-06-03 21:12:26 -05: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 = std::mem::transmute(a);
|
|
|
|
let _: &u32 = std::mem::transmute::<_, &u32>(a);
|
|
|
|
match 0 {
|
|
|
|
0 => std::mem::transmute(x),
|
|
|
|
_ => std::mem::transmute::<_, &&'b u32>(x),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-19 20:16:50 -06:00
|
|
|
fn main() {}
|