diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/union/union-deref.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/union/union-deref.stderr | 11 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/union/union-deref.rs b/src/test/ui/union/union-deref.rs new file mode 100644 index 00000000000..61bbe73354f --- /dev/null +++ b/src/test/ui/union/union-deref.rs @@ -0,0 +1,13 @@ +//! Test the part of RFC 2514 that is about not applying `DerefMut` coercions +//! of union fields. +#![feature(untagged_unions)] + +use std::mem::ManuallyDrop; + +union U<T> { x:(), f: ManuallyDrop<(T,)> } + +fn main() { + let mut u : U<Vec<i32>> = U { x: () }; + unsafe { (*u.f).0 = Vec::new() }; // explicit deref, this compiles + unsafe { u.f.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on union field +} diff --git a/src/test/ui/union/union-deref.stderr b/src/test/ui/union/union-deref.stderr new file mode 100644 index 00000000000..66cc90cbd3d --- /dev/null +++ b/src/test/ui/union/union-deref.stderr @@ -0,0 +1,11 @@ +error: not automatically applying `DerefMut` on union field + --> $DIR/union-deref.rs:12:14 + | +LL | unsafe { u.f.0 = Vec::new() }; + | ^^^ + | + = help: writing to this field calls the destructor for the old value + = help: add an explicit `*` if that is desired, or call `ptr::write` to not run the destructor + +error: aborting due to previous error + |
