]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
1a4d82fc JJ |
2 | // A basic test of using a higher-ranked trait bound. |
3 | ||
c34b1796 | 4 | |
1a4d82fc JJ |
5 | trait FnLike<A,R> { |
6 | fn call(&self, arg: A) -> R; | |
7 | } | |
8 | ||
9 | struct Identity; | |
10 | ||
11 | impl<'a, T> FnLike<&'a T, &'a T> for Identity { | |
12 | fn call(&self, arg: &'a T) -> &'a T { | |
13 | arg | |
14 | } | |
15 | } | |
16 | ||
17 | fn call_repeatedly<F>(f: F) | |
c34b1796 | 18 | where F : for<'a> FnLike<&'a isize, &'a isize> |
1a4d82fc JJ |
19 | { |
20 | let x = 3; | |
21 | let y = f.call(&x); | |
22 | assert_eq!(3, *y); | |
23 | } | |
24 | ||
25 | fn main() { | |
26 | call_repeatedly(Identity); | |
27 | } |