]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-infer-bound-from-trait.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / regions-infer-bound-from-trait.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 type parameters
12 // from trait 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 all of these cases, we can derive a bound for A that is longer
25 // than 'a based on the trait bound of A:
26
27 fn foo1<'a,A:Static>(x: Inv<'a>, a: A) {
28     check_bound(x, a)
29 }
30
31 fn foo2<'a,A:Static>(x: Inv<'static>, a: A) {
32     check_bound(x, a)
33 }
34
35 fn foo3<'a,A:Is<'a>>(x: Inv<'a>, a: A) {
36     check_bound(x, a)
37 }
38
39 // In these cases, there is no trait bound, so we cannot derive any
40 // bound for A and we get an error:
41
42 fn bar1<'a,A>(x: Inv<'a>, a: A) {
43     check_bound(x, a) //~ ERROR parameter type `A` may not live long enough
44 }
45
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
48 }
49
50 fn main() { }