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 // Check that explicit region bounds are allowed on the various
12 // nominal types (but not on other types) and that they are type
15 struct Inv<'a> { // invariant w/r/t 'a
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>);
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
32 fn has_bound<'b>(self, b: Inv<'b>) {
33 //~^ ERROR lifetime parameters or bounds on method `has_bound` do not match
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
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
50 fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
53 fn another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) {}