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
6 #![feature(untagged_unions)]
8 use std::mem::ManuallyDrop;
10 union U1<T> { x:(), f: ManuallyDrop<(T,)> }
12 union U2<T> { x:(), f: (ManuallyDrop<(T,)>,) }
15 let mut u : U1<Vec<i32>> = U1 { x: () };
16 unsafe { (*u.f).0 = Vec::new() }; // explicit deref, this compiles
17 unsafe { u.f.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
18 unsafe { &mut (*u.f).0 }; // explicit deref, this compiles
19 unsafe { &mut u.f.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
20 unsafe { (*u.f).0.push(0) }; // explicit deref, this compiles
21 unsafe { u.f.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
23 let mut u : U2<Vec<i32>> = U2 { x: () };
24 unsafe { (*u.f.0).0 = Vec::new() }; // explicit deref, this compiles
25 unsafe { u.f.0.0 = Vec::new() }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
26 unsafe { &mut (*u.f.0).0 }; // explicit deref, this compiles
27 unsafe { &mut u.f.0.0 }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field
28 unsafe { (*u.f.0).0.push(0) }; // explicit deref, this compiles
29 unsafe { u.f.0.0.push(0) }; //~ERROR not automatically applying `DerefMut` on `ManuallyDrop` union field