File tree 2 files changed +26
-2
lines changed
src/tools/clippy/tests/ui
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 5
5
#![warn(clippy::useless_transmute)]
6
6
#![warn(clippy::transmute_ptr_to_ptr)]
7
7
8
- use std::mem::transmute;
8
+ use std::mem::{size_of, transmute} ;
9
9
10
10
// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
11
11
// valid, which we quote from below.
@@ -75,3 +75,15 @@ fn main() {
75
75
fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 {
76
76
unsafe { in_param as *const [i32; 1] as *const u8 }
77
77
}
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 5
5
#![ warn( clippy:: useless_transmute) ]
6
6
#![ warn( clippy:: transmute_ptr_to_ptr) ]
7
7
8
- use std:: mem:: transmute;
8
+ use std:: mem:: { size_of , transmute} ;
9
9
10
10
// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
11
11
// valid, which we quote from below.
@@ -75,3 +75,15 @@ fn main() {
75
75
fn trigger_do_check_to_emit_error ( in_param : & [ i32 ; 1 ] ) -> * const u8 {
76
76
unsafe { transmute :: < & [ i32 ; 1 ] , * const u8 > ( in_param) }
77
77
}
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