rust/tests/ui/regions/regions-infer-bound-from-trait-self.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.0 KiB
Rust
Raw Normal View History

// Test that we can derive lifetime bounds on `Self` from trait
// inheritance.
trait Static : 'static { }
trait Is<'a> : 'a { }
struct Inv<'a> {
x: Option<&'a mut &'a isize>
}
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 {
fn foo1<'a>(self, x: Inv<'a>) {
check_bound(x, self)
}
}
2014-12-19 11:54:09 +00:00
trait InheritsFromStaticIndirectly : Sized + Static {
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 {
fn foo(self, x: Inv<'a>) {
check_bound(x, self)
}
}
2014-12-19 11:54:09 +00:00
trait InheritsFromIsIndirectly<'a> : Sized + Is<'a> {
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 {
fn foo(self, x: Inv<'a>) {
check_bound(x, self)
//~^ ERROR parameter type `Self` may not live long enough
}
}
fn main() { }