]> git.proxmox.com Git - rustc.git/blame - src/test/ui/regions/regions-infer-bound-from-trait-self.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / regions / regions-infer-bound-from-trait-self.rs
CommitLineData
1a4d82fc
JJ
1// Test that we can derive lifetime bounds on `Self` from trait
2// inheritance.
3
4trait Static : 'static { }
5
6trait Is<'a> : 'a { }
7
8struct Inv<'a> {
9 x: Option<&'a mut &'a isize>
10}
11
12fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }
13
14// In these case, `Self` inherits `'static`.
15
16trait InheritsFromStatic : Sized + 'static {
17 fn foo1<'a>(self, x: Inv<'a>) {
18 check_bound(x, self)
19 }
20}
21trait 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
30trait InheritsFromIs<'a> : Sized + 'a {
31 fn foo(self, x: Inv<'a>) {
32 check_bound(x, self)
33 }
34}
35
36trait 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
44trait 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
51fn main() { }