1 //! An enum must have a well-defined layout to participate in a transmutation.
5 #![feature(transmutability)]
6 #![allow(dead_code, incomplete_features, non_camel_case_types)]
9 use std
::mem
::{Assume, BikeshedIntrinsicFrom}
;
12 pub fn is_maybe_transmutable
<Src
, Dst
>()
14 Dst
: BikeshedIntrinsicFrom
<Src
, Context
, {
25 fn should_reject_repr_rust() {
28 assert
::is_maybe_transmutable
::<repr_rust
, ()>(); //~ ERROR cannot be safely transmuted
29 assert
::is_maybe_transmutable
::<u128
, repr_rust
>(); //~ ERROR cannot be safely transmuted
34 assert
::is_maybe_transmutable
::<repr_rust
, ()>(); //~ ERROR cannot be safely transmuted
35 assert
::is_maybe_transmutable
::<u128
, repr_rust
>(); //~ ERROR cannot be safely transmuted
39 enum repr_rust { A, B }
40 assert
::is_maybe_transmutable
::<repr_rust
, ()>(); //~ ERROR cannot be safely transmuted
41 assert
::is_maybe_transmutable
::<u128
, repr_rust
>(); //~ ERROR cannot be safely transmuted
45 fn should_accept_primitive_reprs()
47 fn should_accept_repr_i8() {
48 #[repr(i8)] enum repr_i8 { V }
49 assert
::is_maybe_transmutable
::<repr_i8
, ()>();
50 assert
::is_maybe_transmutable
::<i8, repr_i8
>();
53 fn should_accept_repr_u8() {
54 #[repr(u8)] enum repr_u8 { V }
55 assert
::is_maybe_transmutable
::<repr_u8
, ()>();
56 assert
::is_maybe_transmutable
::<u8, repr_u8
>();
59 fn should_accept_repr_i16() {
60 #[repr(i16)] enum repr_i16 { V }
61 assert
::is_maybe_transmutable
::<repr_i16
, ()>();
62 assert
::is_maybe_transmutable
::<i16, repr_i16
>();
65 fn should_accept_repr_u16() {
66 #[repr(u16)] enum repr_u16 { V }
67 assert
::is_maybe_transmutable
::<repr_u16
, ()>();
68 assert
::is_maybe_transmutable
::<u16, repr_u16
>();
71 fn should_accept_repr_i32() {
72 #[repr(i32)] enum repr_i32 { V }
73 assert
::is_maybe_transmutable
::<repr_i32
, ()>();
74 assert
::is_maybe_transmutable
::<i32, repr_i32
>();
77 fn should_accept_repr_u32() {
78 #[repr(u32)] enum repr_u32 { V }
79 assert
::is_maybe_transmutable
::<repr_u32
, ()>();
80 assert
::is_maybe_transmutable
::<u32, repr_u32
>();
83 fn should_accept_repr_i64() {
84 #[repr(i64)] enum repr_i64 { V }
85 assert
::is_maybe_transmutable
::<repr_i64
, ()>();
86 assert
::is_maybe_transmutable
::<i64, repr_i64
>();
89 fn should_accept_repr_u64() {
90 #[repr(u64)] enum repr_u64 { V }
91 assert
::is_maybe_transmutable
::<repr_u64
, ()>();
92 assert
::is_maybe_transmutable
::<u64, repr_u64
>();
95 fn should_accept_repr_i128() {
96 #[repr(i128)] enum repr_i128 { V }
97 assert
::is_maybe_transmutable
::<repr_i128
, ()>();
98 assert
::is_maybe_transmutable
::<i128
, repr_i128
>();
101 fn should_accept_repr_u128() {
102 #[repr(u128)] enum repr_u128 { V }
103 assert
::is_maybe_transmutable
::<repr_u128
, ()>();
104 assert
::is_maybe_transmutable
::<u128
, repr_u128
>();
107 fn should_accept_repr_isize() {
108 #[repr(isize)] enum repr_isize { V }
109 assert
::is_maybe_transmutable
::<repr_isize
, ()>();
110 assert
::is_maybe_transmutable
::<isize, repr_isize
>();
113 fn should_accept_repr_usize() {
114 #[repr(usize)] enum repr_usize { V }
115 assert
::is_maybe_transmutable
::<repr_usize
, ()>();
116 assert
::is_maybe_transmutable
::<usize, repr_usize
>();
120 fn should_accept_repr_C() {
121 #[repr(C)] enum repr_c { V }
122 assert
::is_maybe_transmutable
::<repr_c
, ()>();
123 assert
::is_maybe_transmutable
::<i128
, repr_c
>();