blob: 7f5a3a47976c7d38f812fa9fb9a1232657dd2a1c [file] [log] [blame]
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- this data with an anonymous lifetime `'_`...
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
| ^ ...is captured here, requiring it to live as long as `'static`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
help: alternatively, add an explicit `'static` bound to this reference
|
LL | fn a(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:13:14
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- this data with an anonymous lifetime `'_`...
LL | Box::new(v)
| ^ ...is captured here, requiring it to live as long as `'static`
|
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v`
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
help: alternatively, add an explicit `'static` bound to this reference
|
LL | fn b(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:19:14
|
LL | fn c(v: &[u8]) -> Box<dyn Foo> {
| ----- this data with an anonymous lifetime `'_`...
...
LL | Box::new(v)
| ^ ...is captured here, requiring it to live as long as `'static`
|
help: to declare that the trait object captures data from argument `v`, you can add an explicit `'_` lifetime bound
|
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^^^
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/region-object-lifetime-in-coercion.rs:23:14
|
LL | Box::new(v)
| ^
|
note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 22:6...
--> $DIR/region-object-lifetime-in-coercion.rs:22:6
|
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
| ^^
note: ...so that the expression is assignable
--> $DIR/region-object-lifetime-in-coercion.rs:23:14
|
LL | Box::new(v)
| ^
= note: expected `&[u8]`
found `&'a [u8]`
note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 22:9...
--> $DIR/region-object-lifetime-in-coercion.rs:22:9
|
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
| ^^
note: ...so that the expression is assignable
--> $DIR/region-object-lifetime-in-coercion.rs:23:5
|
LL | Box::new(v)
| ^^^^^^^^^^^
= note: expected `std::boxed::Box<(dyn Foo + 'b)>`
found `std::boxed::Box<dyn Foo>`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0495, E0759.
For more information about an error, try `rustc --explain E0495`.