]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs
1 // Test that we are able to infer a suitable kind for this closure
2 // that is just called (`FnMut`).
3
4 fn main() {
5     let mut counter = 0;
6
7     // Here this must be inferred to FnMut so that it can mutate counter,
8     // but we forgot the mut.
9     let tick1 = || {
10         counter += 1;
11     };
12
13     // In turn, tick2 must be inferred to FnMut so that it can call
14     // tick1, but we forgot the mut.
15     let tick2 = || {
16         tick1(); //~ ERROR cannot borrow `tick1` as mutable
17     };
18
19     tick2(); //~ ERROR cannot borrow
20 }