Skip to content

Commit 1e7e745

Browse files
committed
Test another enum niche with multiple ZST alignments
1 parent 4a1e4ea commit 1e7e745

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

src/test/ui/layout/zero-sized-array-enum-niche.rs

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ type AlignedResult = Result<[u32; 0], bool>; //~ ERROR: layout_of
1515
// It was also using the bool niche for the enum tag, which is fine, but
1616
// after the fix, layout decides to use a direct tagged repr instead.
1717

18+
// Here's another case with multiple ZST alignments, where we should
19+
// get the maximal alignment and matching size.
20+
#[rustc_layout(debug)]
21+
enum MultipleAlignments { //~ ERROR: layout_of
22+
Align2([u16; 0]),
23+
Align4([u32; 0]),
24+
Niche(bool),
25+
}
1826

1927
// Tagged repr is clever enough to grow tags to fill any padding, e.g.:
2028
// 1. `T_FF` (one byte of Tag, one byte of padding, two bytes of align=2 Field)

src/test/ui/layout/zero-sized-array-enum-niche.stderr

+124-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,127 @@ error: layout_of(std::result::Result<[u32; 0], bool>) = Layout {
9797
LL | type AlignedResult = Result<[u32; 0], bool>;
9898
| ^^^^^^^^^^^^^^^^^^
9999

100+
error: layout_of(MultipleAlignments) = Layout {
101+
fields: Arbitrary {
102+
offsets: [
103+
Size(0 bytes),
104+
],
105+
memory_index: [
106+
0,
107+
],
108+
},
109+
variants: Multiple {
110+
tag: Initialized {
111+
value: Int(
112+
I8,
113+
false,
114+
),
115+
valid_range: 0..=2,
116+
},
117+
tag_encoding: Direct,
118+
tag_field: 0,
119+
variants: [
120+
Layout {
121+
fields: Arbitrary {
122+
offsets: [
123+
Size(2 bytes),
124+
],
125+
memory_index: [
126+
0,
127+
],
128+
},
129+
variants: Single {
130+
index: 0,
131+
},
132+
abi: Aggregate {
133+
sized: true,
134+
},
135+
largest_niche: None,
136+
align: AbiAndPrefAlign {
137+
abi: Align(2 bytes),
138+
pref: $PREF_ALIGN,
139+
},
140+
size: Size(2 bytes),
141+
},
142+
Layout {
143+
fields: Arbitrary {
144+
offsets: [
145+
Size(4 bytes),
146+
],
147+
memory_index: [
148+
0,
149+
],
150+
},
151+
variants: Single {
152+
index: 1,
153+
},
154+
abi: Aggregate {
155+
sized: true,
156+
},
157+
largest_niche: None,
158+
align: AbiAndPrefAlign {
159+
abi: Align(4 bytes),
160+
pref: $PREF_ALIGN,
161+
},
162+
size: Size(4 bytes),
163+
},
164+
Layout {
165+
fields: Arbitrary {
166+
offsets: [
167+
Size(1 bytes),
168+
],
169+
memory_index: [
170+
0,
171+
],
172+
},
173+
variants: Single {
174+
index: 2,
175+
},
176+
abi: Aggregate {
177+
sized: true,
178+
},
179+
largest_niche: Some(
180+
Niche {
181+
offset: Size(1 bytes),
182+
value: Int(
183+
I8,
184+
false,
185+
),
186+
valid_range: 0..=1,
187+
},
188+
),
189+
align: AbiAndPrefAlign {
190+
abi: Align(1 bytes),
191+
pref: $PREF_ALIGN,
192+
},
193+
size: Size(2 bytes),
194+
},
195+
],
196+
},
197+
abi: Aggregate {
198+
sized: true,
199+
},
200+
largest_niche: Some(
201+
Niche {
202+
offset: Size(0 bytes),
203+
value: Int(
204+
I8,
205+
false,
206+
),
207+
valid_range: 0..=2,
208+
},
209+
),
210+
align: AbiAndPrefAlign {
211+
abi: Align(4 bytes),
212+
pref: $PREF_ALIGN,
213+
},
214+
size: Size(4 bytes),
215+
}
216+
--> $DIR/zero-sized-array-enum-niche.rs:21:1
217+
|
218+
LL | enum MultipleAlignments {
219+
| ^^^^^^^^^^^^^^^^^^^^^^^
220+
100221
error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = Layout {
101222
fields: Arbitrary {
102223
offsets: [
@@ -191,7 +312,7 @@ error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) =
191312
},
192313
size: Size(4 bytes),
193314
}
194-
--> $DIR/zero-sized-array-enum-niche.rs:29:1
315+
--> $DIR/zero-sized-array-enum-niche.rs:37:1
195316
|
196317
LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>;
197318
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -294,10 +415,10 @@ error: layout_of(std::result::Result<[u32; 0], Packed<U16IsZero>>) = Layout {
294415
},
295416
size: Size(4 bytes),
296417
}
297-
--> $DIR/zero-sized-array-enum-niche.rs:36:1
418+
--> $DIR/zero-sized-array-enum-niche.rs:44:1
298419
|
299420
LL | type NicheWinsOverTagged = Result<[u32; 0], Packed<U16IsZero>>;
300421
| ^^^^^^^^^^^^^^^^^^^^^^^^
301422

302-
error: aborting due to 3 previous errors
423+
error: aborting due to 4 previous errors
303424

0 commit comments

Comments
 (0)