]> git.proxmox.com Git - rustc.git/blame - src/test/ui/regions/regions-infer-bound-from-trait.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / regions / regions-infer-bound-from-trait.rs
CommitLineData
1a4d82fc
JJ
1// Test that we can derive lifetime bounds on type parameters
2// from trait 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 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
17fn foo1<'a,A:Static>(x: Inv<'a>, a: A) {
18 check_bound(x, a)
19}
20
21fn foo2<'a,A:Static>(x: Inv<'static>, a: A) {
22 check_bound(x, a)
23}
24
25fn 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
32fn bar1<'a,A>(x: Inv<'a>, a: A) {
33 check_bound(x, a) //~ ERROR parameter type `A` may not live long enough
34}
35
36fn 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
40fn main() { }