also detect DerefMut in nested union fields
This commit is contained in:
parent
ec0924f964
commit
44defaea3a
3 changed files with 36 additions and 16 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue