1 //! Test the behavior of moving out of non-`Copy` union fields.
2 //! Avoid types that `Drop`, we want to focus on moving.
3 #![feature(untagged_unions)]
5 use std::cell::RefCell;
7 fn move_out<T>(x: T) {}
10 f1_nocopy: RefCell<i32>,
11 f2_nocopy: RefCell<i32>,
16 f1_nocopy: RefCell<i32>,
23 // Moving out of a nocopy field prevents accessing other nocopy field.
25 move_out(x.f1_nocopy);
26 move_out(x.f2_nocopy); //~ ERROR use of moved value: `x`
31 // "Moving" out of copy field doesn't prevent later field accesses.
34 move_out(x.f2_nocopy); // no error
39 // Moving out of a nocopy field prevents accessing other copy field.
41 move_out(x.f2_nocopy);
42 move_out(x.f3_copy); //~ ERROR use of moved value: `x`
47 // Cannot move out of union that implements `Drop`.
49 move_out(x.f1_nocopy); //~ ERROR cannot move out of type `U2`, which implements the `Drop`