summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-early-bound-used-in-bound-method.rs
blob: a778dae1ed3156086557b22f940bcd51a2f473b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// run-pass
// Tests that you can use a fn lifetime parameter as part of
// the value for a type parameter in a bound.


trait GetRef<'a> {
    fn get(&self) -> &'a isize;
}

#[derive(Copy, Clone)]
struct Box<'a> {
    t: &'a isize
}

impl<'a> GetRef<'a> for Box<'a> {
    fn get(&self) -> &'a isize {
        self.t
    }
}

impl<'a> Box<'a> {
    fn add<'b,G:GetRef<'b>>(&self, g2: G) -> isize {
        *self.t + *g2.get()
    }
}

pub fn main() {
    let b1 = Box { t: &3 };
    assert_eq!(b1.add(b1), 6);
}