]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / unboxed-closures / unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs
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.
4 //
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.
10
11 // Test that we are able to infer a suitable kind for this closure
12 // that is just called (`FnMut`).
13
14 fn main() {
15     let mut counter = 0;
16
17     // Here this must be inferred to FnMut so that it can mutate counter,
18     // but we forgot the mut.
19     let tick1 = || {
20         counter += 1;
21     };
22
23     // In turn, tick2 must be inferred to FnMut so that it can call
24     // tick1, but we forgot the mut. The error message we currently
25     // get seems... suboptimal.
26     let tick2 = || { //~ ERROR closure cannot assign to immutable local variable `tick1`
27         tick1();
28     };
29
30     tick2(); //~ ERROR cannot borrow
31 }