1 // check-pass
2 //! An array must inherit the alignment of its inner type.
3
4 #![crate_type = "lib"]
5 #![feature(transmutability)]
6 #![allow(dead_code, incomplete_features, non_camel_case_types)]
7
8 mod assert {
9 use std::mem::{Assume, BikeshedIntrinsicFrom};
10 pub struct Context;
11
is_maybe_transmutable<Src, Dst>() where Dst: BikeshedIntrinsicFrom<Src, Context,12 pub fn is_maybe_transmutable<Src, Dst>()
13 where
14 Dst: BikeshedIntrinsicFrom<Src, Context, {
15 Assume::ALIGNMENT
16 .and(Assume::LIFETIMES)
17 .and(Assume::SAFETY)
18 .and(Assume::VALIDITY)
19 }>
20 {}
21 }
22
23 #[derive(Clone, Copy)] #[repr(u8)] enum Ox00 { V = 0x00 }
24 #[derive(Clone, Copy)] #[repr(u8)] enum Ox01 { V = 0x01 }
25 #[derive(Clone, Copy)] #[repr(u8)] enum OxFF { V = 0xFF }
26
27 #[repr(C)]
28 union Uninit {
29 a: (),
30 b: OxFF,
31 }
32
33 #[repr(C, align(2))] struct align_2(Ox00);
34
len_0()35 fn len_0() {
36 #[repr(C)] struct ImplicitlyPadded([align_2; 0], Ox01);
37 #[repr(C)] struct ExplicitlyPadded(Ox01, Uninit);
38
39 #[repr(C)] struct Struct();
40 assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
41 assert::is_maybe_transmutable::<ExplicitlyPadded, ImplicitlyPadded>();
42 }
43
len_1()44 fn len_1() {
45 #[repr(C)] struct ImplicitlyPadded([align_2; 1], Ox01);
46 #[repr(C)] struct ExplicitlyPadded(Ox00, Uninit, Ox01, Uninit);
47
48 #[repr(C)] struct Struct();
49 assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
50 assert::is_maybe_transmutable::<ExplicitlyPadded, ImplicitlyPadded>();
51 }
52
len_2()53 fn len_2() {
54 #[repr(C)] struct ImplicitlyPadded([align_2; 2], Ox01);
55 #[repr(C)] struct ExplicitlyPadded(Ox00, Uninit, Ox00, Uninit, Ox01, Uninit);
56
57 #[repr(C)] struct Struct();
58 assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
59 assert::is_maybe_transmutable::<ExplicitlyPadded, ImplicitlyPadded>();
60 }
61