Skip to content

Commit 45b0c8d

Browse files
committed
Add regression test
1 parent d242a8b commit 45b0c8d

File tree

2 files changed

+253
-0
lines changed

2 files changed

+253
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Test that we produce the same niche range no
2+
//! matter of signendess if the discriminants are the same.
3+
4+
#![feature(rustc_attrs)]
5+
6+
#[repr(u16)]
7+
#[rustc_layout(debug)]
8+
enum UnsignedAroundZero {
9+
//~^ ERROR: layout_of
10+
A = 65535,
11+
B = 0,
12+
C = 1,
13+
}
14+
15+
#[repr(i16)]
16+
#[rustc_layout(debug)]
17+
enum SignedAroundZero {
18+
//~^ ERROR: layout_of
19+
A = -1,
20+
B = 0,
21+
C = 1,
22+
}
23+
24+
fn main() {}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
error: layout_of(UnsignedAroundZero) = Layout {
2+
size: Size(2 bytes),
3+
align: AbiAlign {
4+
abi: Align(2 bytes),
5+
},
6+
backend_repr: Scalar(
7+
Initialized {
8+
value: Int(
9+
I16,
10+
false,
11+
),
12+
valid_range: 0..=65535,
13+
},
14+
),
15+
fields: Arbitrary {
16+
offsets: [
17+
Size(0 bytes),
18+
],
19+
memory_index: [
20+
0,
21+
],
22+
},
23+
largest_niche: None,
24+
uninhabited: false,
25+
variants: Multiple {
26+
tag: Initialized {
27+
value: Int(
28+
I16,
29+
false,
30+
),
31+
valid_range: 0..=65535,
32+
},
33+
tag_encoding: Direct,
34+
tag_field: 0,
35+
variants: [
36+
Layout {
37+
size: Size(2 bytes),
38+
align: AbiAlign {
39+
abi: Align(2 bytes),
40+
},
41+
backend_repr: Memory {
42+
sized: true,
43+
},
44+
fields: Arbitrary {
45+
offsets: [],
46+
memory_index: [],
47+
},
48+
largest_niche: None,
49+
uninhabited: false,
50+
variants: Single {
51+
index: 0,
52+
},
53+
max_repr_align: None,
54+
unadjusted_abi_align: Align(2 bytes),
55+
randomization_seed: 9885373149222004003,
56+
},
57+
Layout {
58+
size: Size(2 bytes),
59+
align: AbiAlign {
60+
abi: Align(2 bytes),
61+
},
62+
backend_repr: Memory {
63+
sized: true,
64+
},
65+
fields: Arbitrary {
66+
offsets: [],
67+
memory_index: [],
68+
},
69+
largest_niche: None,
70+
uninhabited: false,
71+
variants: Single {
72+
index: 1,
73+
},
74+
max_repr_align: None,
75+
unadjusted_abi_align: Align(2 bytes),
76+
randomization_seed: 9885373149222004003,
77+
},
78+
Layout {
79+
size: Size(2 bytes),
80+
align: AbiAlign {
81+
abi: Align(2 bytes),
82+
},
83+
backend_repr: Memory {
84+
sized: true,
85+
},
86+
fields: Arbitrary {
87+
offsets: [],
88+
memory_index: [],
89+
},
90+
largest_niche: None,
91+
uninhabited: false,
92+
variants: Single {
93+
index: 2,
94+
},
95+
max_repr_align: None,
96+
unadjusted_abi_align: Align(2 bytes),
97+
randomization_seed: 9885373149222004003,
98+
},
99+
],
100+
},
101+
max_repr_align: None,
102+
unadjusted_abi_align: Align(2 bytes),
103+
randomization_seed: 2648004449468912780,
104+
}
105+
--> $DIR/wrapping_niche.rs:8:1
106+
|
107+
LL | enum UnsignedAroundZero {
108+
| ^^^^^^^^^^^^^^^^^^^^^^^
109+
110+
error: layout_of(SignedAroundZero) = Layout {
111+
size: Size(2 bytes),
112+
align: AbiAlign {
113+
abi: Align(2 bytes),
114+
},
115+
backend_repr: Scalar(
116+
Initialized {
117+
value: Int(
118+
I16,
119+
true,
120+
),
121+
valid_range: (..=1) | (65535..),
122+
},
123+
),
124+
fields: Arbitrary {
125+
offsets: [
126+
Size(0 bytes),
127+
],
128+
memory_index: [
129+
0,
130+
],
131+
},
132+
largest_niche: Some(
133+
Niche {
134+
offset: Size(0 bytes),
135+
value: Int(
136+
I16,
137+
true,
138+
),
139+
valid_range: (..=1) | (65535..),
140+
},
141+
),
142+
uninhabited: false,
143+
variants: Multiple {
144+
tag: Initialized {
145+
value: Int(
146+
I16,
147+
true,
148+
),
149+
valid_range: (..=1) | (65535..),
150+
},
151+
tag_encoding: Direct,
152+
tag_field: 0,
153+
variants: [
154+
Layout {
155+
size: Size(2 bytes),
156+
align: AbiAlign {
157+
abi: Align(2 bytes),
158+
},
159+
backend_repr: Memory {
160+
sized: true,
161+
},
162+
fields: Arbitrary {
163+
offsets: [],
164+
memory_index: [],
165+
},
166+
largest_niche: None,
167+
uninhabited: false,
168+
variants: Single {
169+
index: 0,
170+
},
171+
max_repr_align: None,
172+
unadjusted_abi_align: Align(2 bytes),
173+
randomization_seed: 2684536712112553499,
174+
},
175+
Layout {
176+
size: Size(2 bytes),
177+
align: AbiAlign {
178+
abi: Align(2 bytes),
179+
},
180+
backend_repr: Memory {
181+
sized: true,
182+
},
183+
fields: Arbitrary {
184+
offsets: [],
185+
memory_index: [],
186+
},
187+
largest_niche: None,
188+
uninhabited: false,
189+
variants: Single {
190+
index: 1,
191+
},
192+
max_repr_align: None,
193+
unadjusted_abi_align: Align(2 bytes),
194+
randomization_seed: 2684536712112553499,
195+
},
196+
Layout {
197+
size: Size(2 bytes),
198+
align: AbiAlign {
199+
abi: Align(2 bytes),
200+
},
201+
backend_repr: Memory {
202+
sized: true,
203+
},
204+
fields: Arbitrary {
205+
offsets: [],
206+
memory_index: [],
207+
},
208+
largest_niche: None,
209+
uninhabited: false,
210+
variants: Single {
211+
index: 2,
212+
},
213+
max_repr_align: None,
214+
unadjusted_abi_align: Align(2 bytes),
215+
randomization_seed: 2684536712112553499,
216+
},
217+
],
218+
},
219+
max_repr_align: None,
220+
unadjusted_abi_align: Align(2 bytes),
221+
randomization_seed: 10738146848450213996,
222+
}
223+
--> $DIR/wrapping_niche.rs:17:1
224+
|
225+
LL | enum SignedAroundZero {
226+
| ^^^^^^^^^^^^^^^^^^^^^
227+
228+
error: aborting due to 2 previous errors
229+

0 commit comments

Comments
 (0)