use std::mem::{size_of, transmute};
-// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
+// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
// valid, which we quote from below.
fn main() {
// We should see an error message for each transmute, and no error messages for
// the casts, since the casts are the recommended fixes.
// e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast
- let _ptr_i32_transmute = unsafe {
- usize::MAX as *const i32
- };
+ let _ptr_i32_transmute = unsafe { usize::MAX as *const i32 };
let ptr_i32 = usize::MAX as *const i32;
// e has type *T, U is *U_0, and either U_0: Sized ...
- let _ptr_i8_transmute = unsafe {
- ptr_i32 as *const i8
- };
+ let _ptr_i8_transmute = unsafe { ptr_i32 as *const i8 };
let _ptr_i8 = ptr_i32 as *const i8;
- let slice_ptr = &[0,1,2,3] as *const [i32];
+ let slice_ptr = &[0, 1, 2, 3] as *const [i32];
// ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast
- let _ptr_to_unsized_transmute = unsafe {
- slice_ptr as *const [u16]
- };
+ let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u16] };
let _ptr_to_unsized = slice_ptr as *const [u16];
// TODO: We could try testing vtable casts here too, but maybe
// we should wait until std::raw::TraitObject is stabilized?
// e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast
- let _usize_from_int_ptr_transmute = unsafe {
- ptr_i32 as usize
- };
+ let _usize_from_int_ptr_transmute = unsafe { ptr_i32 as usize };
let _usize_from_int_ptr = ptr_i32 as usize;
- let array_ref: &[i32; 4] = &[1,2,3,4];
+ let array_ref: &[i32; 4] = &[1, 2, 3, 4];
// e has type &[T; n] and U is *const T; array-ptr-cast
- let _array_ptr_transmute = unsafe {
- array_ref as *const [i32; 4]
- };
+ let _array_ptr_transmute = unsafe { array_ref as *const [i32; 4] };
let _array_ptr = array_ref as *const [i32; 4];
- fn foo(_: usize) -> u8 { 42 }
+ fn foo(_: usize) -> u8 {
+ 42
+ }
// e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast
- let _usize_ptr_transmute = unsafe {
- foo as *const usize
- };
+ let _usize_ptr_transmute = unsafe { foo as *const usize };
let _usize_ptr_transmute = foo as *const usize;
// e is a function pointer type and U is an integer; fptr-addr-cast
- let _usize_from_fn_ptr_transmute = unsafe {
- foo as usize
- };
+ let _usize_from_fn_ptr_transmute = unsafe { foo as usize };
let _usize_from_fn_ptr = foo as *const usize;
}