]> git.lizzy.rs Git - rust.git/blob - tests/ui/expr-if-generic.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / ui / expr-if-generic.rs
1 // run-pass
2
3 fn test_generic<T, F>(expected: T, not_expected: T, eq: F) where
4     T: Clone,
5     F: FnOnce(T, T) -> bool,
6 {
7     let actual: T = if true { expected.clone() } else { not_expected };
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, false, 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}, Pair{a: 2, b: 3}, compare_rec);
27 }
28
29 pub fn main() { test_bool(); test_rec(); }