1 // Test that we cannot mutate an outer variable that is not declared
2 // as `mut` through a closure. Also test that we CAN mutate a moved copy,
3 // unless this is a `Fn` closure. Issue #16749.
5 #![feature(unboxed_closures, tuple_trait)]
9 fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f }
10 fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f }
14 let mut f = to_fn_mut(|| {
15 n += 1; //~ ERROR cannot assign to `n`, as it is not declared as mutable
21 let mut f = to_fn_mut(|| {
28 let mut f = to_fn_mut(move || {
29 // If we just did a straight-forward desugaring, this would
30 // compile, but we do something a bit more subtle, and hence
32 n += 1; //~ ERROR cannot assign
38 let mut f = to_fn_mut(move || {
45 let mut f = to_fn(move || {
46 n += 1; //~ ERROR cannot assign
52 let mut f = to_fn(move || {
53 n += 1; //~ ERROR cannot assign