1 // Tests that two closures cannot simultaneously have mutable
2 // access to the variable, whether that mutable access be used
3 // for direct assignment or for taking mutable ref. Issue #6801.
11 fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
15 let c1 = to_fn_mut(|| x = 4);
16 let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
20 fn set(x: &mut isize) {
26 let c1 = to_fn_mut(|| set(&mut x));
27 let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
33 let c1 = to_fn_mut(|| x = 5);
34 let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
40 let c1 = to_fn_mut(|| x = 5);
41 let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
42 //~^ ERROR cannot borrow `x` as mutable more than once
51 let mut x: Box<_> = Box::new(Foo { f: Box::new(3) });
52 let c1 = to_fn_mut(|| set(&mut *x.f));
53 let c2 = to_fn_mut(|| set(&mut *x.f));
54 //~^ ERROR cannot borrow `x` as mutable more than once