os-rust/tests/ui/regions/region-object-lifetime-in-coercion.rs

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

35 lines
786 B
Rust
Raw Normal View History

// Test that attempts to implicitly coerce a value into an
// object respect the lifetime bound on the object type.
2015-04-17 22:12:20 -07:00
trait Foo {}
2014-10-22 16:53:03 +13:00
impl<'a> Foo for &'a [u8] {}
2019-05-28 14:46:13 -04:00
fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
let x: Box<dyn Foo + 'static> = Box::new(v);
2022-04-01 13:13:25 -04:00
//~^ ERROR lifetime may not live long enough
x
}
2019-05-28 14:46:13 -04:00
fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
Box::new(v)
2022-04-01 13:13:25 -04:00
//~^ ERROR lifetime may not live long enough
}
2019-05-28 14:46:13 -04:00
fn c(v: &[u8]) -> Box<dyn Foo> {
// same as previous case due to RFC 599
Box::new(v)
2022-04-01 13:13:25 -04:00
//~^ ERROR lifetime may not live long enough
}
2019-05-28 14:46:13 -04:00
fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
Box::new(v)
2022-04-01 13:13:25 -04:00
//~^ ERROR lifetime may not live long enough
}
2019-05-28 14:46:13 -04:00
fn e<'a:'b,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
Box::new(v) // OK, thanks to 'a:'b
}
fn main() { }