Skip to content

Commit e05cbfe

Browse files
committed
bug: nesting pattern types in enums doesn't use layout optimizations
1 parent bd41537 commit e05cbfe

File tree

2 files changed

+292
-3
lines changed

2 files changed

+292
-3
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
#![feature(pattern_types)]
1+
#![feature(pattern_types, rustc_attrs)]
22
#![allow(incomplete_features)]
33

4-
// check-pass
4+
#[rustc_layout(debug)]
5+
type X = std::num::NonZeroU32; //~ ERROR layout_of
6+
#[rustc_layout(debug)]
7+
type Y = u32 is 1..; //~ ERROR layout_of
8+
#[rustc_layout(debug)]
9+
type Z = Option<u32 is 1..>; //~ ERROR layout_of
10+
#[rustc_layout(debug)]
11+
type A = Option<std::num::NonZeroU32>; //~ ERROR layout_of
512

613
fn main() {
7-
let x: u32 is 1.. = todo!();
14+
let x: u32 is 1.. = unsafe { std::mem::transmute(42_u32) };
815
}
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
error: layout_of(std::num::NonZeroU32) = Layout {
2+
size: Size(4 bytes),
3+
align: AbiAndPrefAlign {
4+
abi: Align(4 bytes),
5+
pref: Align(8 bytes),
6+
},
7+
abi: Scalar(
8+
Initialized {
9+
value: Int(
10+
I32,
11+
false,
12+
),
13+
valid_range: 1..=4294967295,
14+
},
15+
),
16+
fields: Arbitrary {
17+
offsets: [
18+
Size(0 bytes),
19+
],
20+
memory_index: [
21+
0,
22+
],
23+
},
24+
largest_niche: Some(
25+
Niche {
26+
offset: Size(0 bytes),
27+
value: Int(
28+
I32,
29+
false,
30+
),
31+
valid_range: 1..=4294967295,
32+
},
33+
),
34+
variants: Single {
35+
index: 0,
36+
},
37+
}
38+
--> $DIR/range_patterns.rs:5:1
39+
|
40+
LL | type X = std::num::NonZeroU32;
41+
| ^^^^^^
42+
43+
error: layout_of((u32) is 1..=) = Layout {
44+
size: Size(4 bytes),
45+
align: AbiAndPrefAlign {
46+
abi: Align(4 bytes),
47+
pref: Align(4 bytes),
48+
},
49+
abi: Scalar(
50+
Initialized {
51+
value: Int(
52+
I32,
53+
false,
54+
),
55+
valid_range: 1..=4294967295,
56+
},
57+
),
58+
fields: Primitive,
59+
largest_niche: None,
60+
variants: Single {
61+
index: 0,
62+
},
63+
}
64+
--> $DIR/range_patterns.rs:7:1
65+
|
66+
LL | type Y = u32 is 1..;
67+
| ^^^^^^
68+
69+
error: layout_of(std::option::Option<(u32) is 1..=>) = Layout {
70+
size: Size(8 bytes),
71+
align: AbiAndPrefAlign {
72+
abi: Align(4 bytes),
73+
pref: Align(8 bytes),
74+
},
75+
abi: ScalarPair(
76+
Initialized {
77+
value: Int(
78+
I32,
79+
false,
80+
),
81+
valid_range: 0..=1,
82+
},
83+
Union {
84+
value: Int(
85+
I32,
86+
false,
87+
),
88+
},
89+
),
90+
fields: Arbitrary {
91+
offsets: [
92+
Size(0 bytes),
93+
],
94+
memory_index: [
95+
0,
96+
],
97+
},
98+
largest_niche: Some(
99+
Niche {
100+
offset: Size(0 bytes),
101+
value: Int(
102+
I32,
103+
false,
104+
),
105+
valid_range: 0..=1,
106+
},
107+
),
108+
variants: Multiple {
109+
tag: Initialized {
110+
value: Int(
111+
I32,
112+
false,
113+
),
114+
valid_range: 0..=1,
115+
},
116+
tag_encoding: Direct,
117+
tag_field: 0,
118+
variants: [
119+
Layout {
120+
size: Size(4 bytes),
121+
align: AbiAndPrefAlign {
122+
abi: Align(1 bytes),
123+
pref: Align(8 bytes),
124+
},
125+
abi: Aggregate {
126+
sized: true,
127+
},
128+
fields: Arbitrary {
129+
offsets: [],
130+
memory_index: [],
131+
},
132+
largest_niche: None,
133+
variants: Single {
134+
index: 0,
135+
},
136+
},
137+
Layout {
138+
size: Size(8 bytes),
139+
align: AbiAndPrefAlign {
140+
abi: Align(4 bytes),
141+
pref: Align(8 bytes),
142+
},
143+
abi: ScalarPair(
144+
Initialized {
145+
value: Int(
146+
I32,
147+
false,
148+
),
149+
valid_range: 0..=1,
150+
},
151+
Union {
152+
value: Int(
153+
I32,
154+
false,
155+
),
156+
},
157+
),
158+
fields: Arbitrary {
159+
offsets: [
160+
Size(4 bytes),
161+
],
162+
memory_index: [
163+
0,
164+
],
165+
},
166+
largest_niche: None,
167+
variants: Single {
168+
index: 1,
169+
},
170+
},
171+
],
172+
},
173+
}
174+
--> $DIR/range_patterns.rs:9:1
175+
|
176+
LL | type Z = Option<u32 is 1..>;
177+
| ^^^^^^
178+
179+
error: layout_of(std::option::Option<std::num::NonZeroU32>) = Layout {
180+
size: Size(4 bytes),
181+
align: AbiAndPrefAlign {
182+
abi: Align(4 bytes),
183+
pref: Align(8 bytes),
184+
},
185+
abi: Scalar(
186+
Initialized {
187+
value: Int(
188+
I32,
189+
false,
190+
),
191+
valid_range: (..=0) | (1..),
192+
},
193+
),
194+
fields: Arbitrary {
195+
offsets: [
196+
Size(0 bytes),
197+
],
198+
memory_index: [
199+
0,
200+
],
201+
},
202+
largest_niche: None,
203+
variants: Multiple {
204+
tag: Initialized {
205+
value: Int(
206+
I32,
207+
false,
208+
),
209+
valid_range: (..=0) | (1..),
210+
},
211+
tag_encoding: Niche {
212+
untagged_variant: 1,
213+
niche_variants: 0..=0,
214+
niche_start: 0,
215+
},
216+
tag_field: 0,
217+
variants: [
218+
Layout {
219+
size: Size(0 bytes),
220+
align: AbiAndPrefAlign {
221+
abi: Align(1 bytes),
222+
pref: Align(8 bytes),
223+
},
224+
abi: Aggregate {
225+
sized: true,
226+
},
227+
fields: Arbitrary {
228+
offsets: [],
229+
memory_index: [],
230+
},
231+
largest_niche: None,
232+
variants: Single {
233+
index: 0,
234+
},
235+
},
236+
Layout {
237+
size: Size(4 bytes),
238+
align: AbiAndPrefAlign {
239+
abi: Align(4 bytes),
240+
pref: Align(8 bytes),
241+
},
242+
abi: Scalar(
243+
Initialized {
244+
value: Int(
245+
I32,
246+
false,
247+
),
248+
valid_range: 1..=4294967295,
249+
},
250+
),
251+
fields: Arbitrary {
252+
offsets: [
253+
Size(0 bytes),
254+
],
255+
memory_index: [
256+
0,
257+
],
258+
},
259+
largest_niche: Some(
260+
Niche {
261+
offset: Size(0 bytes),
262+
value: Int(
263+
I32,
264+
false,
265+
),
266+
valid_range: 1..=4294967295,
267+
},
268+
),
269+
variants: Single {
270+
index: 1,
271+
},
272+
},
273+
],
274+
},
275+
}
276+
--> $DIR/range_patterns.rs:11:1
277+
|
278+
LL | type A = Option<std::num::NonZeroU32>;
279+
| ^^^^^^
280+
281+
error: aborting due to 4 previous errors
282+

0 commit comments

Comments
 (0)