File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 55#![warn(clippy::useless_transmute)]
66#![warn(clippy::transmute_ptr_to_ptr)]
77
8- use std::mem::transmute;
8+ use std::mem::{size_of, transmute} ;
99
1010// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
1111// valid, which we quote from below.
@@ -75,3 +75,15 @@ fn main() {
7575fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 {
7676 unsafe { in_param as *const [i32; 1] as *const u8 }
7777}
78+
79+ #[repr(C)]
80+ struct Single(u64);
81+
82+ #[repr(C)]
83+ struct Pair(u32, u32);
84+
85+ fn cannot_be_expressed_as_pointer_cast(in_param: Single) -> Pair {
86+ assert_eq!(size_of::<Single>(), size_of::<Pair>());
87+
88+ unsafe { transmute::<Single, Pair>(in_param) }
89+ }
Original file line number Diff line number Diff line change 55#![ warn( clippy:: useless_transmute) ]
66#![ warn( clippy:: transmute_ptr_to_ptr) ]
77
8- use std:: mem:: transmute;
8+ use std:: mem:: { size_of , transmute} ;
99
1010// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
1111// valid, which we quote from below.
@@ -75,3 +75,15 @@ fn main() {
7575fn trigger_do_check_to_emit_error ( in_param : & [ i32 ; 1 ] ) -> * const u8 {
7676 unsafe { transmute :: < & [ i32 ; 1 ] , * const u8 > ( in_param) }
7777}
78+
79+ #[ repr( C ) ]
80+ struct Single ( u64 ) ;
81+
82+ #[ repr( C ) ]
83+ struct Pair ( u32 , u32 ) ;
84+
85+ fn cannot_be_expressed_as_pointer_cast ( in_param : Single ) -> Pair {
86+ assert_eq ! ( size_of:: <Single >( ) , size_of:: <Pair >( ) ) ;
87+
88+ unsafe { transmute :: < Single , Pair > ( in_param) }
89+ }
You can’t perform that action at this time.
0 commit comments