]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/closure_cap_coerce_many_fail.rs
Rollup merge of #107700 - jyn514:tools-builder, r=Mark-Simulacrum
[rust.git] / tests / ui / closures / closure_cap_coerce_many_fail.rs
1 fn add(a: i32, b: i32) -> i32 {
2     a + b
3 }
4 fn main() {
5     // We shouldn't coerce capturing closure to a function
6     let cap = 0;
7     let _ = match "+" {
8         "+" => add,
9         "-" => |a, b| (a - b + cap) as i32,
10         _ => unimplemented!(),
11     };
12     //~^^^ ERROR `match` arms have incompatible types
13
14
15     // We shouldn't coerce capturing closure to a non-capturing closure
16     let _ = match "+" {
17         "+" => |a, b| (a + b) as i32,
18         "-" => |a, b| (a - b + cap) as i32,
19         _ => unimplemented!(),
20     };
21     //~^^^ ERROR `match` arms have incompatible types
22
23
24     // We shouldn't coerce non-capturing closure to a capturing closure
25     let _ = match "+" {
26         "+" => |a, b| (a + b + cap) as i32,
27         "-" => |a, b| (a - b) as i32,
28         _ => unimplemented!(),
29     };
30     //~^^^ ERROR `match` arms have incompatible types
31
32     // We shouldn't coerce capturing closure to a capturing closure
33     let _ = match "+" {
34         "+" => |a, b| (a + b + cap) as i32,
35         "-" => |a, b| (a - b + cap) as i32,
36         _ => unimplemented!(),
37     };
38     //~^^^ ERROR `match` arms have incompatible types
39 }