about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-08-16 10:24:10 +0200
committerRalf Jung <post@ralfj.de>2020-08-31 10:14:30 +0200
commit44defaea3a2dd2e7e40336d3609df12b83db424a (patch)
treee0d7f02d3a24db1c77603ef088f27bd7b363b56e /src
parentec0924f9649ea472782df6d21595714cb594f038 (diff)
downloadrust-44defaea3a2dd2e7e40336d3609df12b83db424a.tar.gz
rust-44defaea3a2dd2e7e40336d3609df12b83db424a.zip
also detect DerefMut in nested union fields
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/union/union-deref.rs10
-rw-r--r--src/test/ui/union/union-deref.stderr13
2 files changed, 19 insertions, 4 deletions
diff --git a/src/test/ui/union/union-deref.rs b/src/test/ui/union/union-deref.rs
index 61bbe73354f..4578110cd54 100644
--- a/src/test/ui/union/union-deref.rs
+++ b/src/test/ui/union/union-deref.rs
@@ -4,10 +4,16 @@
 
 use std::mem::ManuallyDrop;
 
-union U<T> { x:(), f: ManuallyDrop<(T,)> }
+union U1<T> { x:(), f: ManuallyDrop<(T,)> }
+
+union U2<T> { x:(), f: (ManuallyDrop<(T,)>,) }
 
 fn main() {
-    let mut u : U<Vec<i32>> = U { x: () };
+    let mut u : U1<Vec<i32>> = U1 { 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
+
+    let mut u : U2<Vec<i32>> = U2 { x: () };
+    unsafe { (*u.f.0).0 = Vec::new() }; // explicit deref, this compiles
+    unsafe { u.f.0.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
index 66cc90cbd3d..93374436d2f 100644
--- a/src/test/ui/union/union-deref.stderr
+++ b/src/test/ui/union/union-deref.stderr
@@ -1,5 +1,5 @@
 error: not automatically applying `DerefMut` on union field
-  --> $DIR/union-deref.rs:12:14
+  --> $DIR/union-deref.rs:14:14
    |
 LL |     unsafe { u.f.0 = Vec::new() };
    |              ^^^
@@ -7,5 +7,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
+error: not automatically applying `DerefMut` on union field
+  --> $DIR/union-deref.rs:18:14
+   |
+LL |     unsafe { u.f.0.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 2 previous errors