]> git.lizzy.rs Git - rust.git/blob - tests/ui/binding/expr-match-generic.rs
Rollup merge of #106805 - madsravn:master, r=compiler-errors
[rust.git] / tests / ui / binding / expr-match-generic.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3
4 type compare<T> = extern "Rust" fn(T, T) -> bool;
5
6 fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
7   let actual: T = match true { true => { expected.clone() }, _ => panic!("wat") };
8     assert!((eq(expected, actual)));
9 }
10
11 fn test_bool() {
12     fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; }
13     test_generic::<bool>(true, compare_bool);
14 }
15
16 #[derive(Clone)]
17 struct Pair {
18     a: isize,
19     b: isize,
20 }
21
22 fn test_rec() {
23     fn compare_rec(t1: Pair, t2: Pair) -> bool {
24         t1.a == t2.a && t1.b == t2.b
25     }
26     test_generic::<Pair>(Pair {a: 1, b: 2}, compare_rec);
27 }
28
29 pub fn main() { test_bool(); test_rec(); }