Skip to content

Commit

Permalink
Add failing test for projections used as union field type
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 13, 2023
1 parent 4a04f25 commit 829cf09
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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`.

0 comments on commit 829cf09

Please sign in to comment.