]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/closure_no_cap_coerce_many_unsafe_1.rs
Rollup merge of #106779 - RReverser:patch-2, r=Mark-Simulacrum
[rust.git] / tests / ui / closures / closure_no_cap_coerce_many_unsafe_1.rs
1 // run-pass
2 // Ensure we get correct unsafe function after coercion
3 unsafe fn add(a: i32, b: i32) -> i32 {
4     a + b
5 }
6 fn main() {
7     // We can coerce non-capturing closure to unsafe function
8     let foo = match "+" {
9         "+" => add,
10         "-" => |a, b| (a - b) as i32,
11         _ => unimplemented!(),
12     };
13     assert_eq!(unsafe { foo(5, 5) }, 10);
14
15
16     // We can coerce unsafe function to non-capturing closure
17     let foo = match "-" {
18         "-" => |a, b| (a - b) as i32,
19         "+" => add,
20         _ => unimplemented!(),
21     };
22     assert_eq!(unsafe { foo(5, 5) }, 0);
23 }