]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unboxed-closures-mutate-upvar.rs
650bb17bb7758f9ce60d81d2dcc7ec38ff7cab7b
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that we cannot mutate an outer variable that is not declared
12 // as `mut` through a closure. Also test that we CAN mutate a moved copy,
13 // unless this is a `Fn` closure. Issue #16749.
15 #![feature(unboxed_closures)]
19 fn to_fn
<A
,F
:Fn
<A
>>(f
: F
) -> F { f }
20 fn to_fn_mut
<A
,F
:FnMut
<A
>>(f
: F
) -> F { f }
24 let mut f
= to_fn_mut(|| { //~ ERROR closure cannot assign
31 let mut f
= to_fn_mut(|| {
38 let mut f
= to_fn_mut(move || {
39 // If we just did a straight-forward desugaring, this would
40 // compile, but we do something a bit more subtle, and hence
42 n
+= 1; //~ ERROR cannot assign
48 let mut f
= to_fn_mut(move || {
55 let mut f
= to_fn(move || {
56 n
+= 1; //~ ERROR cannot assign
62 let mut f
= to_fn(move || {
63 n
+= 1; //~ ERROR cannot assign