rust/src/test/compile-fail/regions-infer-bound-from-trait-self.rs

62 lines
1.5 KiB
Rust
Raw Normal View History

// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// 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 int>
}
fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { }
// In these case, `Self` inherits `'static`.
2014-12-19 05:54:09 -06:00
trait InheritsFromStatic : Sized + 'static {
fn foo1<'a>(self, x: Inv<'a>) {
check_bound(x, self)
}
}
2014-12-19 05:54:09 -06: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 05:54:09 -06:00
trait InheritsFromIs<'a> : Sized + 'a {
fn foo(self, x: Inv<'a>) {
check_bound(x, self)
}
}
2014-12-19 05:54:09 -06: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 05:54:09 -06: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() { }