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.
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.
11 // Test that we can derive lifetime bounds on type parameters
12 // from trait inheritance.
14 trait Static : 'static { }
19 x: Option<&'a mut &'a isize>
22 fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }
24 // In all of these cases, we can derive a bound for A that is longer
25 // than 'a based on the trait bound of A:
27 fn foo1<'a,A:Static>(x: Inv<'a>, a: A) {
31 fn foo2<'a,A:Static>(x: Inv<'static>, a: A) {
35 fn foo3<'a,A:Is<'a>>(x: Inv<'a>, a: A) {
39 // In these cases, there is no trait bound, so we cannot derive any
40 // bound for A and we get an error:
42 fn bar1<'a,A>(x: Inv<'a>, a: A) {
43 check_bound(x, a) //~ ERROR parameter type `A` may not live long enough
46 fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) {
47 check_bound(x, a) //~ ERROR parameter type `A` may not live long enough