]> git.lizzy.rs Git - rust.git/blob - src/test/ui/repr/repr-transparent.rs
Auto merge of #53830 - davidtwco:issue-53228, r=nikomatsakis
[rust.git] / src / test / ui / repr / repr-transparent.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // This file tests repr(transparent)-related errors reported during typeck. Other errors
12 // that are reported earlier and therefore preempt these are tested in:
13 // - repr-transparent-other-reprs.rs
14 // - repr-transparent-other-items.rs
15
16 #![feature(repr_align)]
17
18 use std::marker::PhantomData;
19
20 #[repr(transparent)]
21 struct NoFields; //~ ERROR needs exactly one non-zero-sized field
22
23 #[repr(transparent)]
24 struct ContainsOnlyZst(()); //~ ERROR needs exactly one non-zero-sized field
25
26 #[repr(transparent)]
27 struct ContainsOnlyZstArray([bool; 0]); //~ ERROR needs exactly one non-zero-sized field
28
29 #[repr(transparent)]
30 struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
31 //~^ ERROR needs exactly one non-zero-sized field
32
33 #[repr(transparent)]
34 struct MultipleNonZst(u8, u8); //~ ERROR needs exactly one non-zero-sized field
35
36 trait Mirror { type It: ?Sized; }
37 impl<T: ?Sized> Mirror for T { type It = Self; }
38
39 #[repr(transparent)]
40 pub struct StructWithProjection(f32, <f32 as Mirror>::It);
41 //~^ ERROR needs exactly one non-zero-sized field
42
43 #[repr(transparent)]
44 struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1
45
46 #[repr(align(32))]
47 struct ZstAlign32<T>(PhantomData<T>);
48
49 #[repr(transparent)]
50 struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1
51
52 fn main() {}