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