]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-infer-bound-from-trait.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / regions / regions-infer-bound-from-trait.rs
1 // Test that we can derive lifetime bounds on type parameters
2 // from trait 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 all of these cases, we can derive a bound for A that is longer
15 // than 'a based on the trait bound of A:
16
17 fn foo1<'a,A:Static>(x: Inv<'a>, a: A) {
18 check_bound(x, a)
19 }
20
21 fn foo2<'a,A:Static>(x: Inv<'static>, a: A) {
22 check_bound(x, a)
23 }
24
25 fn foo3<'a,A:Is<'a>>(x: Inv<'a>, a: A) {
26 check_bound(x, a)
27 }
28
29 // In these cases, there is no trait bound, so we cannot derive any
30 // bound for A and we get an error:
31
32 fn bar1<'a,A>(x: Inv<'a>, a: A) {
33 check_bound(x, a) //~ ERROR parameter type `A` may not live long enough
34 }
35
36 fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) {
37 check_bound(x, a) //~ ERROR parameter type `A` may not live long enough
38 }
39
40 fn main() { }