1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
4 //! Test the part of RFC 2514 that is about not applying `DerefMut` coercions
7 use std::mem::ManuallyDrop;
9 union U1<T> { x:(), f: ManuallyDrop<(T,)> }
11 union U2<T> { x:(), f: (ManuallyDrop<(T,)>,) }
14 let mut u : U1<Vec<i32>> = U1 { x: () };
15 unsafe { (*u.f).0 = Vec::new() }; // explicit deref, this compiles
16 unsafe { u.f.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
17 unsafe { &mut (*u.f).0 }; // explicit deref, this compiles
18 unsafe { &mut u.f.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
19 unsafe { (*u.f).0.push(0) }; // explicit deref, this compiles
20 unsafe { u.f.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
22 let mut u : U2<Vec<i32>> = U2 { x: () };
23 unsafe { (*u.f.0).0 = Vec::new() }; // explicit deref, this compiles
24 unsafe { u.f.0.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
25 unsafe { &mut (*u.f.0).0 }; // explicit deref, this compiles
26 unsafe { &mut u.f.0.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
27 unsafe { (*u.f.0).0.push(0) }; // explicit deref, this compiles
28 unsafe { u.f.0.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field