Skip to content

Commit d5ab3a0

Browse files
committed
Add test cases for #104802.
1 parent 4f4f22b commit d5ab3a0

File tree

2 files changed

+120
-11
lines changed

2 files changed

+120
-11
lines changed

tests/ui/layout/debug.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
2-
#![feature(never_type, rustc_attrs, type_alias_impl_trait)]
2+
#![feature(never_type, rustc_attrs, type_alias_impl_trait, repr_simd)]
33
#![crate_type = "lib"]
44

55
#[rustc_layout(debug)]
6+
#[derive(Copy, Clone)]
67
enum E { Foo, Bar(!, i32, i32) } //~ ERROR: layout_of
78

89
#[rustc_layout(debug)]
@@ -35,6 +36,26 @@ pub union Y { //~ ERROR: layout_of
3536
a: [u16; 0],
3637
}
3738

39+
#[rustc_layout(debug)]
40+
#[repr(packed(1))]
41+
union P1 { x: u32 } //~ ERROR: layout_of
42+
43+
#[rustc_layout(debug)]
44+
#[repr(packed(1))]
45+
union P2 { x: (u32, u32) } //~ ERROR: layout_of
46+
47+
#[repr(simd)]
48+
#[derive(Copy, Clone)]
49+
struct F32x4(f32, f32, f32, f32);
50+
51+
#[rustc_layout(debug)]
52+
#[repr(packed(1))]
53+
union P3 { x: F32x4 } //~ ERROR: layout_of
54+
55+
#[rustc_layout(debug)]
56+
#[repr(packed(1))]
57+
union P4 { x: E } //~ ERROR: layout_of
58+
3859
#[rustc_layout(debug)]
3960
type X = std::mem::MaybeUninit<u8>; //~ ERROR: layout_of
4061

tests/ui/layout/debug.stderr

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ error: layout_of(E) = Layout {
8181
],
8282
},
8383
}
84-
--> $DIR/debug.rs:6:1
84+
--> $DIR/debug.rs:7:1
8585
|
8686
LL | enum E { Foo, Bar(!, i32, i32) }
8787
| ^^^^^^
@@ -125,7 +125,7 @@ error: layout_of(S) = Layout {
125125
index: 0,
126126
},
127127
}
128-
--> $DIR/debug.rs:9:1
128+
--> $DIR/debug.rs:10:1
129129
|
130130
LL | struct S { f1: i32, f2: (), f3: i32 }
131131
| ^^^^^^^^
@@ -147,7 +147,7 @@ error: layout_of(U) = Layout {
147147
index: 0,
148148
},
149149
}
150-
--> $DIR/debug.rs:12:1
150+
--> $DIR/debug.rs:13:1
151151
|
152152
LL | union U { f1: (i32, i32), f3: i32 }
153153
| ^^^^^^^
@@ -276,7 +276,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
276276
],
277277
},
278278
}
279-
--> $DIR/debug.rs:15:1
279+
--> $DIR/debug.rs:16:1
280280
|
281281
LL | type Test = Result<i32, i32>;
282282
| ^^^^^^^^^
@@ -302,7 +302,7 @@ error: layout_of(i32) = Layout {
302302
index: 0,
303303
},
304304
}
305-
--> $DIR/debug.rs:18:1
305+
--> $DIR/debug.rs:19:1
306306
|
307307
LL | type T = impl std::fmt::Debug;
308308
| ^^^^^^
@@ -324,7 +324,7 @@ error: layout_of(V) = Layout {
324324
index: 0,
325325
},
326326
}
327-
--> $DIR/debug.rs:21:1
327+
--> $DIR/debug.rs:22:1
328328
|
329329
LL | pub union V {
330330
| ^^^^^^^^^^^
@@ -346,7 +346,7 @@ error: layout_of(W) = Layout {
346346
index: 0,
347347
},
348348
}
349-
--> $DIR/debug.rs:27:1
349+
--> $DIR/debug.rs:28:1
350350
|
351351
LL | pub union W {
352352
| ^^^^^^^^^^^
@@ -368,11 +368,99 @@ error: layout_of(Y) = Layout {
368368
index: 0,
369369
},
370370
}
371-
--> $DIR/debug.rs:33:1
371+
--> $DIR/debug.rs:34:1
372372
|
373373
LL | pub union Y {
374374
| ^^^^^^^^^^^
375375

376+
error: layout_of(P1) = Layout {
377+
size: Size(4 bytes),
378+
align: AbiAndPrefAlign {
379+
abi: Align(1 bytes),
380+
pref: $PREF_ALIGN,
381+
},
382+
abi: Aggregate {
383+
sized: true,
384+
},
385+
fields: Union(
386+
1,
387+
),
388+
largest_niche: None,
389+
variants: Single {
390+
index: 0,
391+
},
392+
}
393+
--> $DIR/debug.rs:41:1
394+
|
395+
LL | union P1 { x: u32 }
396+
| ^^^^^^^^
397+
398+
error: layout_of(P2) = Layout {
399+
size: Size(8 bytes),
400+
align: AbiAndPrefAlign {
401+
abi: Align(1 bytes),
402+
pref: $PREF_ALIGN,
403+
},
404+
abi: Aggregate {
405+
sized: true,
406+
},
407+
fields: Union(
408+
1,
409+
),
410+
largest_niche: None,
411+
variants: Single {
412+
index: 0,
413+
},
414+
}
415+
--> $DIR/debug.rs:45:1
416+
|
417+
LL | union P2 { x: (u32, u32) }
418+
| ^^^^^^^^
419+
420+
error: layout_of(P3) = Layout {
421+
size: Size(16 bytes),
422+
align: AbiAndPrefAlign {
423+
abi: Align(1 bytes),
424+
pref: $PREF_ALIGN,
425+
},
426+
abi: Aggregate {
427+
sized: true,
428+
},
429+
fields: Union(
430+
1,
431+
),
432+
largest_niche: None,
433+
variants: Single {
434+
index: 0,
435+
},
436+
}
437+
--> $DIR/debug.rs:53:1
438+
|
439+
LL | union P3 { x: F32x4 }
440+
| ^^^^^^^^
441+
442+
error: layout_of(P4) = Layout {
443+
size: Size(12 bytes),
444+
align: AbiAndPrefAlign {
445+
abi: Align(1 bytes),
446+
pref: $PREF_ALIGN,
447+
},
448+
abi: Aggregate {
449+
sized: true,
450+
},
451+
fields: Union(
452+
1,
453+
),
454+
largest_niche: None,
455+
variants: Single {
456+
index: 0,
457+
},
458+
}
459+
--> $DIR/debug.rs:57:1
460+
|
461+
LL | union P4 { x: E }
462+
| ^^^^^^^^
463+
376464
error: layout_of(std::mem::MaybeUninit<u8>) = Layout {
377465
size: Size(1 bytes),
378466
align: AbiAndPrefAlign {
@@ -395,10 +483,10 @@ error: layout_of(std::mem::MaybeUninit<u8>) = Layout {
395483
index: 0,
396484
},
397485
}
398-
--> $DIR/debug.rs:39:1
486+
--> $DIR/debug.rs:60:1
399487
|
400488
LL | type X = std::mem::MaybeUninit<u8>;
401489
| ^^^^^^
402490

403-
error: aborting due to 9 previous errors
491+
error: aborting due to 13 previous errors
404492

0 commit comments

Comments
 (0)