Skip to content

Commit 829cf09

Browse files
Add failing test for projections used as union field type
1 parent 4a04f25 commit 829cf09

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This is currently not possible to use projections as union field's type.
2+
3+
#![crate_type = "lib"]
4+
5+
pub trait Identity {
6+
type Identity;
7+
}
8+
9+
impl<T> Identity for T {
10+
type Identity = Self;
11+
}
12+
13+
pub type Foo = u8;
14+
15+
pub union Bar {
16+
a: <Foo as Identity>::Identity, //~ ERROR
17+
b: u8,
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0740]: unions cannot contain fields that may need dropping
2+
--> $DIR/projection-as-union-type.rs:16:5
3+
|
4+
LL | a: <Foo as Identity>::Identity,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
8+
help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
9+
|
10+
LL | a: std::mem::ManuallyDrop<<Foo as Identity>::Identity>,
11+
| +++++++++++++++++++++++ +
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0740`.

0 commit comments

Comments
 (0)