Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for casting pointer to union with unsized tail #122724

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/ui/cast/unsized-union-ice.rs
Original file line number Diff line number Diff line change
@@ -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() {}
23 changes: 23 additions & 0 deletions tests/ui/cast/unsized-union-ice.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading