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.
7 fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
11 let c1 = to_fn_mut(|| x = 4);
12 let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
16 fn set(x: &mut isize) {
22 let c1 = to_fn_mut(|| set(&mut x));
23 let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
29 let c1 = to_fn_mut(|| x = 5);
30 let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
36 let c1 = to_fn_mut(|| x = 5);
37 let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
38 //~^ ERROR cannot borrow `x` as mutable more than once
47 let mut x: Box<_> = Box::new(Foo { f: Box::new(3) });
48 let c1 = to_fn_mut(|| set(&mut *x.f));
49 let c2 = to_fn_mut(|| set(&mut *x.f));
50 //~^ ERROR cannot borrow `x` as mutable more than once