]> git.proxmox.com Git - rustc.git/blame - src/test/ui/repr/repr-transparent.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / repr / repr-transparent.rs
CommitLineData
2c00a5a8
XL
1// This file tests repr(transparent)-related errors reported during typeck. Other errors
2// that are reported earlier and therefore preempt these are tested in:
3// - repr-transparent-other-reprs.rs
4// - repr-transparent-other-items.rs
5
dfeec247 6#![feature(transparent_unions)]
2c00a5a8
XL
7
8use std::marker::PhantomData;
9
10#[repr(transparent)]
136023e0 11struct NoFields;
2c00a5a8
XL
12
13#[repr(transparent)]
136023e0 14struct ContainsOnlyZst(());
2c00a5a8
XL
15
16#[repr(transparent)]
136023e0 17struct ContainsOnlyZstArray([bool; 0]);
2c00a5a8
XL
18
19#[repr(transparent)]
20struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
2c00a5a8
XL
21
22#[repr(transparent)]
136023e0
XL
23struct ContainsZstAndNonZst((), [i32; 2]);
24
25#[repr(transparent)]
26struct MultipleNonZst(u8, u8); //~ ERROR needs at most one non-zero-sized field
2c00a5a8
XL
27
28trait Mirror { type It: ?Sized; }
29impl<T: ?Sized> Mirror for T { type It = Self; }
30
31#[repr(transparent)]
32pub struct StructWithProjection(f32, <f32 as Mirror>::It);
136023e0 33//~^ ERROR needs at most one non-zero-sized field
2c00a5a8
XL
34
35#[repr(transparent)]
36struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1
37
38#[repr(align(32))]
39struct ZstAlign32<T>(PhantomData<T>);
40
41#[repr(transparent)]
42struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1
b7449926 43
dc9dc135 44#[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum
136023e0 45enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0
dc9dc135
XL
46
47#[repr(transparent)]
136023e0 48enum FieldlessEnum {
dc9dc135
XL
49 Foo,
50}
51
136023e0
XL
52#[repr(transparent)]
53enum UnitFieldEnum {
54 Foo(()),
55}
56
dc9dc135
XL
57#[repr(transparent)]
58enum TooManyFieldsEnum {
59 Foo(u32, String),
60}
136023e0 61//~^^^ ERROR transparent enum needs at most one non-zero-sized field, but has 2
dc9dc135
XL
62
63#[repr(transparent)]
136023e0 64enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2
dc9dc135
XL
65 Foo(String),
66 Bar,
67}
68
dfeec247
XL
69#[repr(transparent)]
70enum NontrivialAlignZstEnum {
71 Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
72}
73
74#[repr(transparent)]
75enum GenericAlignEnum<T> {
76 Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
77}
78
dc9dc135 79#[repr(transparent)]
136023e0 80union UnitUnion {
dc9dc135
XL
81 u: (),
82}
83
84#[repr(transparent)]
136023e0 85union TooManyFields { //~ ERROR transparent union needs at most one non-zero-sized field, but has 2
dc9dc135
XL
86 u: u32,
87 s: i32
88}
89
b7449926 90fn main() {}