]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-early-bound-used-in-bound-method.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-early-bound-used-in-bound-method.rs
1 // run-pass
2 // Tests that you can use a fn lifetime parameter as part of
3 // the value for a type parameter in a bound.
4
5
6 trait GetRef<'a> {
7     fn get(&self) -> &'a isize;
8 }
9
10 #[derive(Copy, Clone)]
11 struct Box<'a> {
12     t: &'a isize
13 }
14
15 impl<'a> GetRef<'a> for Box<'a> {
16     fn get(&self) -> &'a isize {
17         self.t
18     }
19 }
20
21 impl<'a> Box<'a> {
22     fn add<'b,G:GetRef<'b>>(&self, g2: G) -> isize {
23         *self.t + *g2.get()
24     }
25 }
26
27 pub fn main() {
28     let b1 = Box { t: &3 };
29     assert_eq!(b1.add(b1), 6);
30 }