]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-infer-bound-from-trait-self.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / regions / regions-infer-bound-from-trait-self.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that we can derive lifetime bounds on `Self` from trait
12 // inheritance.
13
14 trait Static : 'static { }
15
16 trait Is<'a> : 'a { }
17
18 struct Inv<'a> {
19     x: Option<&'a mut &'a isize>
20 }
21
22 fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }
23
24 // In these case, `Self` inherits `'static`.
25
26 trait InheritsFromStatic : Sized + 'static {
27     fn foo1<'a>(self, x: Inv<'a>) {
28         check_bound(x, self)
29     }
30 }
31 trait InheritsFromStaticIndirectly : Sized + Static {
32     fn foo1<'a>(self, x: Inv<'a>) {
33         check_bound(x, self)
34     }
35 }
36
37
38 // In these case, `Self` inherits `'a`.
39
40 trait InheritsFromIs<'a> : Sized + 'a {
41     fn foo(self, x: Inv<'a>) {
42         check_bound(x, self)
43     }
44 }
45
46 trait InheritsFromIsIndirectly<'a> : Sized + Is<'a> {
47     fn foo(self, x: Inv<'a>) {
48         check_bound(x, self)
49     }
50 }
51
52 // In this case, `Self` inherits nothing.
53
54 trait InheritsFromNothing<'a> : Sized {
55     fn foo(self, x: Inv<'a>) {
56         check_bound(x, self)
57             //~^ ERROR parameter type `Self` may not live long enough
58     }
59 }
60
61 fn main() { }