]>
Commit | Line | Data |
---|---|---|
064997fb FG |
1 | // check-pass |
2 | //! The fields of a struct should be laid out in lexical order. | |
3 | ||
4 | #![crate_type = "lib"] | |
5 | #![feature(transmutability)] | |
6 | #![allow(dead_code)] | |
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, { |
15 | Assume::ALIGNMENT | |
16 | .and(Assume::LIFETIMES) | |
17 | .and(Assume::SAFETY) | |
18 | .and(Assume::VALIDITY) | |
19 | }> | |
064997fb FG |
20 | {} |
21 | } | |
22 | ||
23 | #[repr(u8)] enum V0 { V = 0 } | |
24 | #[repr(u8)] enum V1 { V = 1 } | |
25 | #[repr(u8)] enum V2 { V = 2 } | |
26 | ||
27 | #[repr(C)] struct S01(V0, V1); | |
28 | #[repr(C)] struct S012(V0, V1, V2); | |
29 | ||
30 | fn should_order_tag_and_fields_correctly() { | |
31 | // An implementation that (incorrectly) arranges S01 as [0x01, 0x00] will, | |
32 | // in principle, reject this transmutation. | |
33 | assert::is_transmutable::<S01, V0>(); | |
34 | // Again, but with one more field. | |
35 | assert::is_transmutable::<S012, S01>(); | |
36 | } |