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 failing test for projections used as union field type #106808

Closed
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
18 changes: 18 additions & 0 deletions tests/ui/union/projection-as-union-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is currently not possible to use projections as union field's type.

#![crate_type = "lib"]

pub trait Identity {
type Identity;
}

impl<T> Identity for T {
type Identity = Self;
}

pub type Foo = u8;

pub union Bar {
a: <Foo as Identity>::Identity, //~ ERROR
b: u8,
}
15 changes: 15 additions & 0 deletions tests/ui/union/projection-as-union-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/projection-as-union-type.rs:16:5
|
LL | a: <Foo as Identity>::Identity,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
|
LL | a: std::mem::ManuallyDrop<<Foo as Identity>::Identity>,
| +++++++++++++++++++++++ +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0740`.