1 //! Test the part of RFC 2514 that is about not applying `DerefMut` coercions
3 #![feature(untagged_unions)]
5 use std::mem::ManuallyDrop;
7 union U1<T> { x:(), f: ManuallyDrop<(T,)> }
9 union U2<T> { x:(), f: (ManuallyDrop<(T,)>,) }
12 let mut u : U1<Vec<i32>> = U1 { x: () };
13 unsafe { (*u.f).0 = Vec::new() }; // explicit deref, this compiles
14 unsafe { u.f.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
15 unsafe { &mut (*u.f).0 }; // explicit deref, this compiles
16 unsafe { &mut u.f.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
17 unsafe { (*u.f).0.push(0) }; // explicit deref, this compiles
18 unsafe { u.f.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
20 let mut u : U2<Vec<i32>> = U2 { x: () };
21 unsafe { (*u.f.0).0 = Vec::new() }; // explicit deref, this compiles
22 unsafe { u.f.0.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
23 unsafe { &mut (*u.f.0).0 }; // explicit deref, this compiles
24 unsafe { &mut u.f.0.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
25 unsafe { (*u.f.0).0.push(0) }; // explicit deref, this compiles
26 unsafe { u.f.0.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field