diff --git a/tests/ui/union/projection-as-union-type.rs b/tests/ui/union/projection-as-union-type.rs new file mode 100644 index 0000000000000..a983fd7f5032e --- /dev/null +++ b/tests/ui/union/projection-as-union-type.rs @@ -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 Identity for T { + type Identity = Self; +} + +pub type Foo = u8; + +pub union Bar { + a: ::Identity, //~ ERROR + b: u8, +} diff --git a/tests/ui/union/projection-as-union-type.stderr b/tests/ui/union/projection-as-union-type.stderr new file mode 100644 index 0000000000000..77630081d9eb9 --- /dev/null +++ b/tests/ui/union/projection-as-union-type.stderr @@ -0,0 +1,15 @@ +error[E0740]: unions cannot contain fields that may need dropping + --> $DIR/projection-as-union-type.rs:16:5 + | +LL | a: ::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<::Identity>, + | +++++++++++++++++++++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0740`.