6 use std::mem::transmute as my_transmute;
7 use std::vec::Vec as MyVec;
9 fn my_vec() -> MyVec<i32> {
13 #[allow(needless_lifetimes)]
14 #[deny(useless_transmute)]
15 unsafe fn _generic<'a, T, U: 'a>(t: &'a T) {
16 let _: &'a T = core::intrinsics::transmute(t);
17 //~^ ERROR transmute from a type (`&'a T`) to itself
19 let _: &'a U = core::intrinsics::transmute(t);
22 #[deny(transmute_ptr_to_ref)]
23 unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
24 let _: &T = std::mem::transmute(p);
25 //~^ ERROR transmute from a pointer type (`*const T`) to a reference type (`&T`)
27 //~| SUGGESTION = &*p;
30 let _: &mut T = std::mem::transmute(m);
31 //~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
33 //~| SUGGESTION = &mut *m;
34 let _: &mut T = &mut *m;
36 let _: &T = std::mem::transmute(m);
37 //~^ ERROR transmute from a pointer type (`*mut T`) to a reference type (`&T`)
39 //~| SUGGESTION = &*m;
42 let _: &T = std::mem::transmute(o);
43 //~^ ERROR transmute from a pointer type (`*const U`) to a reference type (`&T`)
45 //~| SUGGESTION = &*(o as *const T);
46 let _: &T = &*(o as *const T);
48 let _: &mut T = std::mem::transmute(om);
49 //~^ ERROR transmute from a pointer type (`*mut U`) to a reference type (`&mut T`)
51 //~| SUGGESTION = &mut *(om as *mut T);
52 let _: &mut T = &mut *(om as *mut T);
54 let _: &T = std::mem::transmute(om);
55 //~^ ERROR transmute from a pointer type (`*mut U`) to a reference type (`&T`)
57 //~| SUGGESTION = &*(om as *const T);
58 let _: &T = &*(om as *const T);
61 #[deny(useless_transmute)]
64 let _: Vec<i32> = core::intrinsics::transmute(my_vec());
65 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to itself
67 let _: Vec<i32> = core::mem::transmute(my_vec());
68 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to itself
70 let _: Vec<i32> = std::intrinsics::transmute(my_vec());
71 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to itself
73 let _: Vec<i32> = std::mem::transmute(my_vec());
74 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to itself
76 let _: Vec<i32> = my_transmute(my_vec());
77 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to itself
79 let _: Vec<u32> = core::intrinsics::transmute(my_vec());
80 let _: Vec<u32> = core::mem::transmute(my_vec());
81 let _: Vec<u32> = std::intrinsics::transmute(my_vec());
82 let _: Vec<u32> = std::mem::transmute(my_vec());
83 let _: Vec<u32> = my_transmute(my_vec());
87 #[deny(crosspointer_transmute)]
89 let mut vec: Vec<i32> = vec![];
90 let vec_const_ptr: *const Vec<i32> = &vec as *const Vec<i32>;
91 let vec_mut_ptr: *mut Vec<i32> = &mut vec as *mut Vec<i32>;
94 let _: Vec<i32> = core::intrinsics::transmute(vec_const_ptr);
95 //~^ ERROR transmute from a type (`*const collections::vec::Vec<i32>`) to the type that it points to (`collections::vec::Vec<i32>`)
97 let _: Vec<i32> = core::intrinsics::transmute(vec_mut_ptr);
98 //~^ ERROR transmute from a type (`*mut collections::vec::Vec<i32>`) to the type that it points to (`collections::vec::Vec<i32>`)
100 let _: *const Vec<i32> = core::intrinsics::transmute(my_vec());
101 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to a pointer to that type (`*const collections::vec::Vec<i32>`)
103 let _: *mut Vec<i32> = core::intrinsics::transmute(my_vec());
104 //~^ ERROR transmute from a type (`collections::vec::Vec<i32>`) to a pointer to that type (`*mut collections::vec::Vec<i32>`)