]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-bound-missing-bound-in-impl.rs
rollup merge of #21151: brson/beta
[rust.git] / src / test / compile-fail / regions-bound-missing-bound-in-impl.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 // Check that explicit region bounds are allowed on the various
12 // nominal types (but not on other types) and that they are type
13 // checked.
14
15 struct Inv<'a> { // invariant w/r/t 'a
16     x: &'a mut &'a isize
17 }
18
19 pub trait Foo<'a, 't> {
20     fn no_bound<'b>(self, b: Inv<'b>);
21     fn has_bound<'b:'a>(self, b: Inv<'b>);
22     fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
23     fn okay_bound<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
24     fn another_bound<'x: 'a>(self, x: Inv<'x>);
25 }
26
27
28 impl<'a, 't> Foo<'a, 't> for &'a isize {
29     fn no_bound<'b:'a>(self, b: Inv<'b>) {
30         //~^ ERROR lifetime parameters or bounds on method `no_bound` do not match
31     }
32
33     fn has_bound<'b>(self, b: Inv<'b>) {
34         //~^ ERROR lifetime parameters or bounds on method `has_bound` do not match
35     }
36
37     fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
38         //~^ ERROR method `wrong_bound1` has an incompatible type for trait
39         //
40         // Note: This is a terrible error message. It is caused
41         // because, in the trait, 'b is early bound, and in the impl,
42         // 'c is early bound, so -- after substitution -- the
43         // lifetimes themselves look isomorphic.  We fail because the
44         // lifetimes that appear in the types are in the wrong
45         // order. This should really be fixed by keeping more
46         // information about the lifetime declarations in the trait so
47         // that we can compare better to the impl, even in cross-crate
48         // cases.
49     }
50
51     fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
52     }
53
54     fn another_bound<'x: 't>(self, x: Inv<'x>) {}
55 }
56
57 fn main() { }