Skip to content

Commit 433449a

Browse files
authored
Rollup merge of rust-lang#122724 - lukas-code:unsized-union-cast-ice-test, r=compiler-errors
add test for casting pointer to union with unsized tail closes rust-lang#122581
2 parents f773124 + 7b21c1a commit 433449a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Diff for: tests/ui/cast/unsized-union-ice.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/122581
2+
// This used to ICE, because the union was unsized and the pointer casting code
3+
// assumed that non-struct ADTs must be sized.
4+
5+
union Union {
6+
val: std::mem::ManuallyDrop<[u8]>,
7+
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
8+
}
9+
10+
fn cast(ptr: *const ()) -> *const Union {
11+
ptr as _
12+
}
13+
14+
fn main() {}

Diff for: tests/ui/cast/unsized-union-ice.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/unsized-union-ice.rs:6:10
3+
|
4+
LL | val: std::mem::ManuallyDrop<[u8]>,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: within `ManuallyDrop<[u8]>`, the trait `Sized` is not implemented for `[u8]`, which is required by `ManuallyDrop<[u8]>: Sized`
8+
note: required because it appears within the type `ManuallyDrop<[u8]>`
9+
--> $SRC_DIR/core/src/mem/manually_drop.rs:LL:COL
10+
= note: no field of a union may have a dynamically sized type
11+
= help: change the field's type to have a statically known size
12+
help: borrowed types always have a statically known size
13+
|
14+
LL | val: &std::mem::ManuallyDrop<[u8]>,
15+
| +
16+
help: the `Box` type always has a statically known size and allocates its contents in the heap
17+
|
18+
LL | val: Box<std::mem::ManuallyDrop<[u8]>>,
19+
| ++++ +
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)