1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
4 //! Test the behavior of moving out of non-`Copy` union fields.
5 //! Avoid types that `Drop`, we want to focus on moving.
6 #![feature(untagged_unions)]
8 use std::cell::RefCell;
10 fn move_out<T>(x: T) {}
13 f1_nocopy: RefCell<i32>,
14 f2_nocopy: RefCell<i32>,
19 f1_nocopy: RefCell<i32>,
26 // Moving out of a nocopy field prevents accessing other nocopy field.
28 move_out(x.f1_nocopy);
29 move_out(x.f2_nocopy); //~ ERROR use of moved value: `x`
34 // "Moving" out of copy field doesn't prevent later field accesses.
37 move_out(x.f2_nocopy); // no error
42 // Moving out of a nocopy field prevents accessing other copy field.
44 move_out(x.f2_nocopy);
45 move_out(x.f3_copy); //~ ERROR use of moved value: `x`
50 // Cannot move out of union that implements `Drop`.
52 move_out(x.f1_nocopy); //~ ERROR cannot move out of type `U2`, which implements the `Drop`