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> { get(&self) -> &'a isize7 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> { get(&self) -> &'a isize16 fn get(&self) -> &'a isize { 17 self.t 18 } 19 } 20 21 impl<'a> Box<'a> { add<'b,G:GetRef<'b>>(&self, g2: G) -> isize22 fn add<'b,G:GetRef<'b>>(&self, g2: G) -> isize { 23 *self.t + *g2.get() 24 } 25 } 26 main()27pub fn main() { 28 let b1 = Box { t: &3 }; 29 assert_eq!(b1.add(b1), 6); 30 } 31