]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Test that we can derive lifetime bounds on `Self` from trait |
2 | // inheritance. | |
3 | ||
4 | trait Static : 'static { } | |
5 | ||
6 | trait Is<'a> : 'a { } | |
7 | ||
8 | struct Inv<'a> { | |
9 | x: Option<&'a mut &'a isize> | |
10 | } | |
11 | ||
12 | fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { } | |
13 | ||
14 | // In these case, `Self` inherits `'static`. | |
15 | ||
16 | trait InheritsFromStatic : Sized + 'static { | |
17 | fn foo1<'a>(self, x: Inv<'a>) { | |
18 | check_bound(x, self) | |
19 | } | |
20 | } | |
21 | trait InheritsFromStaticIndirectly : Sized + Static { | |
22 | fn foo1<'a>(self, x: Inv<'a>) { | |
23 | check_bound(x, self) | |
24 | } | |
25 | } | |
26 | ||
27 | ||
28 | // In these case, `Self` inherits `'a`. | |
29 | ||
30 | trait InheritsFromIs<'a> : Sized + 'a { | |
31 | fn foo(self, x: Inv<'a>) { | |
32 | check_bound(x, self) | |
33 | } | |
34 | } | |
35 | ||
36 | trait InheritsFromIsIndirectly<'a> : Sized + Is<'a> { | |
37 | fn foo(self, x: Inv<'a>) { | |
38 | check_bound(x, self) | |
39 | } | |
40 | } | |
41 | ||
42 | // In this case, `Self` inherits nothing. | |
43 | ||
44 | trait InheritsFromNothing<'a> : Sized { | |
45 | fn foo(self, x: Inv<'a>) { | |
46 | check_bound(x, self) | |
47 | //~^ ERROR parameter type `Self` may not live long enough | |
48 | } | |
49 | } | |
50 | ||
51 | fn main() { } |