]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/closure-captures.rs
Auto merge of #105145 - Ayush1325:sequential-remote-server, r=Mark-Simulacrum
[rust.git] / src / test / ui / nll / closure-captures.rs
1 // Some cases with closures that might be problems
2
3 // Should have one error per assignment
4
5 fn one_closure(x: i32) {
6     ||
7     x = 1; //~ ERROR
8     move ||
9     x = 1; //~ ERROR
10 }
11
12 fn two_closures(x: i32) {
13     || {
14         ||
15         x = 1; //~ ERROR
16     };
17     move || {
18         ||
19         x = 1; //~ ERROR
20     };
21 }
22
23 fn fn_ref<F: Fn()>(f: F) -> F { f }
24
25 fn two_closures_ref_mut(mut x: i32) {
26     fn_ref(|| {
27         || //~ ERROR
28          x = 1;}
29     );
30     fn_ref(move || {
31         ||  //~ ERROR
32     x = 1;});
33 }
34
35 // This still gives two messages, but it requires two things to be fixed.
36 fn two_closures_ref(x: i32) {
37     fn_ref(|| {
38         || //~ ERROR
39          x = 1;} //~ ERROR
40     );
41     fn_ref(move || {
42         ||  //~ ERROR
43     x = 1;}); //~ ERROR
44 }
45
46 fn two_closures_two_refs(x: &mut i32) {
47     fn_ref(|| {
48         || //~ ERROR
49         *x = 1;});
50     fn_ref(move || {
51         || //~ ERROR
52         *x = 1;});
53 }
54
55 fn main() {}