]>
Commit | Line | Data |
---|---|---|
064997fb FG |
1 | //! ALL valid bit patterns of the source must be valid bit patterns of the |
2 | //! destination type, unless validity is assumed. | |
3 | ||
4 | #![crate_type = "lib"] | |
5 | #![feature(transmutability)] | |
6 | #![allow(dead_code, incomplete_features, non_camel_case_types)] | |
7 | ||
8 | mod assert { | |
f2b60f7d | 9 | use std::mem::{Assume, BikeshedIntrinsicFrom}; |
064997fb FG |
10 | pub struct Context; |
11 | ||
12 | pub fn is_transmutable<Src, Dst>() | |
13 | where | |
f2b60f7d FG |
14 | Dst: BikeshedIntrinsicFrom<Src, Context, { Assume::SAFETY }> |
15 | // validity is NOT assumed --------------^^^^^^^^^^^^^^^^^^ | |
064997fb FG |
16 | {} |
17 | } | |
18 | ||
19 | #[derive(Clone, Copy)] #[repr(u8)] enum Ox00 { V = 0x00 } | |
20 | #[derive(Clone, Copy)] #[repr(u8)] enum Ox7F { V = 0x7F } | |
21 | #[derive(Clone, Copy)] #[repr(u8)] enum OxFF { V = 0xFF } | |
22 | ||
23 | fn test() { | |
24 | #[repr(C)] | |
25 | union A { | |
26 | a: Ox00, | |
27 | b: Ox7F, | |
28 | } | |
29 | ||
30 | #[repr(C)] | |
31 | union B { | |
32 | a: Ox7F, | |
33 | b: OxFF, | |
34 | } | |
35 | ||
36 | assert::is_transmutable::<A, B>(); //~ ERROR cannot be safely transmuted | |
37 | assert::is_transmutable::<B, A>(); //~ ERROR cannot be safely transmuted | |
38 | } |