The following code:
#[derive(Clone, Copy)]
struct B<Element> {
_marker: std::marker::PhantomData<Element>
}
union AOrB<Element> {
a: (),
b: B<Element>,
}
gives me this error:
error[E0740]: unions cannot contain fields that may need dropping
--> src/lib.rs:8:5
|
8 | b: B<Element>,
| ^^^^^^^^^^^^^
|
= 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
|
8 | b: std::mem::ManuallyDrop<B<Element>>,
| +++++++++++++++++++++++ +
For more information about this error, try `rustc --explain E0740`.
error: could not compile `playground` due to previous error
The error says that B
doesn't implement Copy
, however, B
does implement Copy
. Am I missing something? Or is this a bug?