2014-08-27 21:46:52 -04:00
|
|
|
// Check that explicit region bounds are allowed on the various
|
|
|
|
// nominal types (but not on other types) and that they are type
|
|
|
|
// checked.
|
|
|
|
|
|
|
|
struct Inv<'a> { // invariant w/r/t 'a
|
2015-01-08 21:54:35 +11:00
|
|
|
x: &'a mut &'a isize
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
|
2015-01-14 13:43:17 -08:00
|
|
|
pub trait Foo<'a, 't> {
|
2014-08-27 21:46:52 -04:00
|
|
|
fn no_bound<'b>(self, b: Inv<'b>);
|
|
|
|
fn has_bound<'b:'a>(self, b: Inv<'b>);
|
|
|
|
fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
|
2018-06-27 15:25:18 -07:00
|
|
|
fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
|
2015-01-14 13:43:17 -08:00
|
|
|
fn okay_bound<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
|
2015-02-12 10:29:52 -05:00
|
|
|
fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
|
2015-01-14 13:43:17 -08:00
|
|
|
impl<'a, 't> Foo<'a, 't> for &'a isize {
|
2014-08-27 21:46:52 -04:00
|
|
|
fn no_bound<'b:'a>(self, b: Inv<'b>) {
|
|
|
|
//~^ ERROR lifetime parameters or bounds on method `no_bound` do not match
|
|
|
|
}
|
|
|
|
|
|
|
|
fn has_bound<'b>(self, b: Inv<'b>) {
|
|
|
|
//~^ ERROR lifetime parameters or bounds on method `has_bound` do not match
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
|
2016-05-25 21:12:35 +03:00
|
|
|
//~^ ERROR method not compatible with trait
|
2020-01-08 20:02:10 +03:00
|
|
|
//~| ERROR method not compatible with trait
|
2014-08-27 21:46:52 -04:00
|
|
|
//
|
|
|
|
// Note: This is a terrible error message. It is caused
|
|
|
|
// because, in the trait, 'b is early bound, and in the impl,
|
|
|
|
// 'c is early bound, so -- after substitution -- the
|
|
|
|
// lifetimes themselves look isomorphic. We fail because the
|
|
|
|
// lifetimes that appear in the types are in the wrong
|
|
|
|
// order. This should really be fixed by keeping more
|
|
|
|
// information about the lifetime declarations in the trait so
|
|
|
|
// that we can compare better to the impl, even in cross-crate
|
|
|
|
// cases.
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:25:18 -07:00
|
|
|
fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) {
|
|
|
|
//~^ ERROR lifetime parameters or bounds on method `wrong_bound2` do not match the trait
|
|
|
|
}
|
|
|
|
|
2015-01-14 13:43:17 -08:00
|
|
|
fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
2015-01-14 13:43:17 -08:00
|
|
|
|
2015-04-18 11:23:14 -04:00
|
|
|
fn another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) {
|
2016-10-14 10:10:22 -04:00
|
|
|
//~^ ERROR E0276
|
2015-04-18 11:23:14 -04:00
|
|
|
}
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|