From 7e1a65dce1d13d02de8e0ffafad15538556cb7b9 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 20 Sep 2019 13:53:46 +0200 Subject: [PATCH] Ensure we do not treat all unions as not having any drop glue. --- src/test/ui/union/union-custom-drop.rs | 19 +++++++++++++++ src/test/ui/union/union-custom-drop.stderr | 28 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/test/ui/union/union-custom-drop.rs create mode 100644 src/test/ui/union/union-custom-drop.stderr diff --git a/src/test/ui/union/union-custom-drop.rs b/src/test/ui/union/union-custom-drop.rs new file mode 100644 index 0000000000000..8f816cc1b737c --- /dev/null +++ b/src/test/ui/union/union-custom-drop.rs @@ -0,0 +1,19 @@ +// test for a union with a field that's a union with a manual impl Drop +// Ensures we do not treat all unions as not having any drop glue. + +#![feature(untagged_unions)] + +union Foo { + bar: Bar, //~ ERROR unions may not contain fields that need dropping +} + +union Bar { + a: i32, + b: u32, +} + +impl Drop for Bar { + fn drop(&mut self) {} +} + +fn main() {} diff --git a/src/test/ui/union/union-custom-drop.stderr b/src/test/ui/union/union-custom-drop.stderr new file mode 100644 index 0000000000000..8e4e5dd40fd3f --- /dev/null +++ b/src/test/ui/union/union-custom-drop.stderr @@ -0,0 +1,28 @@ +error[E0601]: `main` function not found in crate `union_custom_drop` + --> $DIR/union-custom-drop.rs:4:1 + | +LL | / #![feature(untagged_unions)] +LL | | +LL | | union Foo { +LL | | bar: Bar, +... | +LL | | } +LL | | } + | |_^ consider adding a `main` function to `$DIR/union-custom-drop.rs` + +error[E0740]: unions may not contain fields that need dropping + --> $DIR/union-custom-drop.rs:7:5 + | +LL | bar: Bar, + | ^^^^^^^^ + | +note: `std::mem::ManuallyDrop` can be used to wrap the type + --> $DIR/union-custom-drop.rs:7:5 + | +LL | bar: Bar, + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0601, E0740. +For more information about an error, try `rustc --explain E0601`.