summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-infer-bound-from-trait-self.rs
blob: d15bfffe9d92659ab02607409719b57af3c5540f (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Test that we can derive lifetime bounds on `Self` from trait
// inheritance.

trait Static : 'static { }

trait Is<'a> : 'a { }

struct Inv<'a> {
    x: Option<&'a mut &'a isize>
}

fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }

// In these case, `Self` inherits `'static`.

trait InheritsFromStatic : Sized + 'static {
    fn foo1<'a>(self, x: Inv<'a>) {
        check_bound(x, self)
    }
}
trait InheritsFromStaticIndirectly : Sized + Static {
    fn foo1<'a>(self, x: Inv<'a>) {
        check_bound(x, self)
    }
}


// In these case, `Self` inherits `'a`.

trait InheritsFromIs<'a> : Sized + 'a {
    fn foo(self, x: Inv<'a>) {
        check_bound(x, self)
    }
}

trait InheritsFromIsIndirectly<'a> : Sized + Is<'a> {
    fn foo(self, x: Inv<'a>) {
        check_bound(x, self)
    }
}

// In this case, `Self` inherits nothing.

trait InheritsFromNothing<'a> : Sized {
    fn foo(self, x: Inv<'a>) {
        check_bound(x, self)
            //~^ ERROR parameter type `Self` may not live long enough
    }
}

fn main() { }