]> git.lizzy.rs Git - rust.git/blob - tests/ui/higher-rank-trait-bounds/hrtb-fn-like-trait.rs
Rollup merge of #106797 - FawazTirmizi:dev/issues/104284, r=bjorn3
[rust.git] / tests / ui / higher-rank-trait-bounds / hrtb-fn-like-trait.rs
1 // run-pass
2 // A basic test of using a higher-ranked trait bound.
3
4
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)
18     where F : for<'a> FnLike<&'a isize, &'a isize>
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 }