diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-19 18:03:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 18:03:54 +0100 |
| commit | 433449a900b9286db70aa8c57cd723a84cb558f0 (patch) | |
| tree | e31f6ac9466feda205d1f9b5f221c6a9b3443e5d | |
| parent | f7731243d908fe6b3cdf1654a3e8266cceafc5b8 (diff) | |
| parent | 7b21c1a4578a7a705f3d104e886ba5192a80db54 (diff) | |
| download | rust-433449a900b9286db70aa8c57cd723a84cb558f0.tar.gz rust-433449a900b9286db70aa8c57cd723a84cb558f0.zip | |
Rollup merge of #122724 - lukas-code:unsized-union-cast-ice-test, r=compiler-errors
add test for casting pointer to union with unsized tail closes https://github.com/rust-lang/rust/issues/122581
| -rw-r--r-- | tests/ui/cast/unsized-union-ice.rs | 14 | ||||
| -rw-r--r-- | tests/ui/cast/unsized-union-ice.stderr | 23 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/cast/unsized-union-ice.rs b/tests/ui/cast/unsized-union-ice.rs new file mode 100644 index 00000000000..11aefe57f1d --- /dev/null +++ b/tests/ui/cast/unsized-union-ice.rs @@ -0,0 +1,14 @@ +// Regression test for https://github.com/rust-lang/rust/issues/122581 +// This used to ICE, because the union was unsized and the pointer casting code +// assumed that non-struct ADTs must be sized. + +union Union { + val: std::mem::ManuallyDrop<[u8]>, + //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time +} + +fn cast(ptr: *const ()) -> *const Union { + ptr as _ +} + +fn main() {} diff --git a/tests/ui/cast/unsized-union-ice.stderr b/tests/ui/cast/unsized-union-ice.stderr new file mode 100644 index 00000000000..05f86457829 --- /dev/null +++ b/tests/ui/cast/unsized-union-ice.stderr @@ -0,0 +1,23 @@ +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/unsized-union-ice.rs:6:10 + | +LL | val: std::mem::ManuallyDrop<[u8]>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `ManuallyDrop<[u8]>`, the trait `Sized` is not implemented for `[u8]`, which is required by `ManuallyDrop<[u8]>: Sized` +note: required because it appears within the type `ManuallyDrop<[u8]>` + --> $SRC_DIR/core/src/mem/manually_drop.rs:LL:COL + = note: no field of a union may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | val: &std::mem::ManuallyDrop<[u8]>, + | + +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | val: Box<std::mem::ManuallyDrop<[u8]>>, + | ++++ + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. |
