2014-08-28 01:46:52 +00:00
|
|
|
// Test that we can derive lifetime bounds on `Self` from trait
|
|
|
|
// inheritance.
|
|
|
|
|
|
|
|
trait Static : 'static { }
|
|
|
|
|
|
|
|
trait Is<'a> : 'a { }
|
|
|
|
|
|
|
|
struct Inv<'a> {
|
2015-01-08 10:54:35 +00:00
|
|
|
x: Option<&'a mut &'a isize>
|
2014-08-28 01:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }
|
|
|
|
|
|
|
|
// In these case, `Self` inherits `'static`.
|
|
|
|
|
2014-12-19 11:54:09 +00:00
|
|
|
trait InheritsFromStatic : Sized + 'static {
|
2014-08-28 01:46:52 +00:00
|
|
|
fn foo1<'a>(self, x: Inv<'a>) {
|
|
|
|
check_bound(x, self)
|
|
|
|
}
|
|
|
|
}
|
2014-12-19 11:54:09 +00:00
|
|
|
trait InheritsFromStaticIndirectly : Sized + Static {
|
2014-08-28 01:46:52 +00:00
|
|
|
fn foo1<'a>(self, x: Inv<'a>) {
|
|
|
|
check_bound(x, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// In these case, `Self` inherits `'a`.
|
|
|
|
|
2014-12-19 11:54:09 +00:00
|
|
|
trait InheritsFromIs<'a> : Sized + 'a {
|
2014-08-28 01:46:52 +00:00
|
|
|
fn foo(self, x: Inv<'a>) {
|
|
|
|
check_bound(x, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 11:54:09 +00:00
|
|
|
trait InheritsFromIsIndirectly<'a> : Sized + Is<'a> {
|
2014-08-28 01:46:52 +00:00
|
|
|
fn foo(self, x: Inv<'a>) {
|
|
|
|
check_bound(x, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In this case, `Self` inherits nothing.
|
|
|
|
|
2014-12-19 11:54:09 +00:00
|
|
|
trait InheritsFromNothing<'a> : Sized {
|
2014-08-28 01:46:52 +00:00
|
|
|
fn foo(self, x: Inv<'a>) {
|
|
|
|
check_bound(x, self)
|
|
|
|
//~^ ERROR parameter type `Self` may not live long enough
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|