4 // Test that move closures compile properly with `capture_disjoint_fields` enabled.
16 fn struct_contains_ref_to_another_struct() {
18 struct T<'a>(&'a mut S);
20 let mut s = S("s".into());
24 t.0.0 = "new s".into();
37 let mut t = T(S("s".into()));
39 t.0.0 = "new S".into();
45 let mut t = T(S("s".into()));
47 println!("{:?}", t.0);
49 t.0.0 = "new S".into();
50 println!("{:?}", t.0.0);
57 struct A<'a>(&'a mut String, &'a mut String);
58 // Test that reborrowing works as expected for move closures
59 // by attempting a disjoint capture through a reference.
60 fn disjoint_via_ref() {
61 let mut x = String::new();
62 let mut y = String::new();
64 let mut a = A(&mut x, &mut y);
67 let mut c1 = move || {
71 let mut c2 = move || {
79 // Test that even if a path is moved into the closure, the closure is not FnOnce
80 // if the path is not moved by the closure call.
81 fn data_moved_but_not_fn_once() {
82 let x = Box::new(10i32);
85 // *x has type i32 which is Copy. So even though the box `x` will be moved
86 // into the closure, `x` is never moved when the closure is called, i.e. the
87 // ownership stays with the closure and therefore we can call the function multiple times.
97 struct_contains_ref_to_another_struct();
102 data_moved_but_not_fn_once();