| error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement |
| --> $DIR/region-object-lifetime-in-coercion.rs:12: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 used and required to live as long as `'static` here |
| | |
| 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]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement |
| --> $DIR/region-object-lifetime-in-coercion.rs:19:14 |
| | |
| LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> { |
| | ----- this data with an anonymous lifetime `'_`... |
| LL | Box::new(v) |
| | ^ ...is used and required to live as long as `'static` here |
| | |
| note: `'static` lifetime requirement introduced by the return type |
| --> $DIR/region-object-lifetime-in-coercion.rs:18:33 |
| | |
| LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> { |
| | ^^^^^^^ `'static` requirement introduced here |
| LL | Box::new(v) |
| | ----------- because of this returned expression |
| 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]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement |
| --> $DIR/region-object-lifetime-in-coercion.rs:27:14 |
| | |
| LL | fn c(v: &[u8]) -> Box<dyn Foo> { |
| | ----- this data with an anonymous lifetime `'_`... |
| ... |
| LL | Box::new(v) |
| | ^ ...is used and required to live as long as `'static` here |
| | |
| note: `'static` lifetime requirement introduced by the return type |
| --> $DIR/region-object-lifetime-in-coercion.rs:24:23 |
| | |
| LL | fn c(v: &[u8]) -> Box<dyn Foo> { |
| | ^^^^^^^ `'static` requirement introduced here |
| ... |
| LL | Box::new(v) |
| | ----------- because of this returned expression |
| 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:33:14 |
| | |
| LL | Box::new(v) |
| | ^ |
| | |
| note: first, the lifetime cannot outlive the lifetime `'a` as defined here... |
| --> $DIR/region-object-lifetime-in-coercion.rs:32: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:33:14 |
| | |
| LL | Box::new(v) |
| | ^ |
| = note: expected `&[u8]` |
| found `&'a [u8]` |
| note: but, the lifetime must be valid for the lifetime `'b` as defined here... |
| --> $DIR/region-object-lifetime-in-coercion.rs:32:9 |
| | |
| LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> { |
| | ^^ |
| note: ...so that the types are compatible |
| --> $DIR/region-object-lifetime-in-coercion.rs:33:5 |
| | |
| LL | Box::new(v) |
| | ^^^^^^^^^^^ |
| = note: expected `Box<(dyn Foo + 'b)>` |
| found `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`. |