]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/closure_no_cap_coerce_many_unsafe_0.rs
Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisa
[rust.git] / tests / ui / closures / closure_no_cap_coerce_many_unsafe_0.rs
1 // revisions: mir thir
2 // [thir]compile-flags: -Z thir-unsafeck
3
4 // Ensure we get unsafe function after coercion
5 unsafe fn add(a: i32, b: i32) -> i32 {
6     a + b
7 }
8 fn main() {
9     // We can coerce non-capturing closure to unsafe function
10     let foo = match "+" {
11         "+" => add,
12         "-" => |a, b| (a - b) as i32,
13         _ => unimplemented!(),
14     };
15     let result: i32 = foo(5, 5); //~ ERROR call to unsafe function
16
17
18     // We can coerce unsafe function to non-capturing closure
19     let foo = match "+" {
20         "-" => |a, b| (a - b) as i32,
21         "+" => add,
22         _ => unimplemented!(),
23     };
24     let result: i32 = foo(5, 5); //~ ERROR call to unsafe function
25 }