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