]>
Commit | Line | Data |
---|---|---|
f035d41b | 1 | error: lifetime may not live long enough |
04454e1e | 2 | --> $DIR/region-object-lifetime-in-coercion.rs:12:12 |
48663c56 | 3 | | |
dc9dc135 | 4 | LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> { |
f035d41b | 5 | | - let's call the lifetime of this reference `'1` |
dc9dc135 | 6 | LL | let x: Box<dyn Foo + 'static> = Box::new(v); |
f035d41b | 7 | | ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static` |
04454e1e FG |
8 | | |
9 | help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` | |
10 | | | |
11 | LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> { | |
12 | | ~~ | |
13 | help: alternatively, add an explicit `'static` bound to this reference | |
14 | | | |
15 | LL | fn a(v: &'static [u8]) -> Box<dyn Foo + 'static> { | |
16 | | ~~~~~~~~~~~~~ | |
48663c56 | 17 | |
f035d41b | 18 | error: lifetime may not live long enough |
04454e1e | 19 | --> $DIR/region-object-lifetime-in-coercion.rs:19:5 |
48663c56 | 20 | | |
dc9dc135 | 21 | LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> { |
f035d41b | 22 | | - let's call the lifetime of this reference `'1` |
48663c56 | 23 | LL | Box::new(v) |
f035d41b | 24 | | ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` |
04454e1e FG |
25 | | |
26 | help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` | |
27 | | | |
28 | LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> { | |
29 | | ~~ | |
30 | help: alternatively, add an explicit `'static` bound to this reference | |
31 | | | |
32 | LL | fn b(v: &'static [u8]) -> Box<dyn Foo + 'static> { | |
33 | | ~~~~~~~~~~~~~ | |
48663c56 | 34 | |
f9f354fc | 35 | error: lifetime may not live long enough |
04454e1e | 36 | --> $DIR/region-object-lifetime-in-coercion.rs:27:5 |
48663c56 | 37 | | |
dc9dc135 | 38 | LL | fn c(v: &[u8]) -> Box<dyn Foo> { |
f9f354fc | 39 | | - let's call the lifetime of this reference `'1` |
48663c56 XL |
40 | ... |
41 | LL | Box::new(v) | |
f9f354fc | 42 | | ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` |
04454e1e FG |
43 | | |
44 | help: to declare that the trait object captures data from argument `v`, you can add an explicit `'_` lifetime bound | |
45 | | | |
46 | LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> { | |
47 | | ++++ | |
48663c56 XL |
48 | |
49 | error: lifetime may not live long enough | |
04454e1e | 50 | --> $DIR/region-object-lifetime-in-coercion.rs:33:5 |
48663c56 | 51 | | |
dc9dc135 | 52 | LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> { |
48663c56 XL |
53 | | -- -- lifetime `'b` defined here |
54 | | | | |
55 | | lifetime `'a` defined here | |
56 | LL | Box::new(v) | |
5099ac24 | 57 | | ^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` |
60c5eb7d XL |
58 | | |
59 | = help: consider adding the following bound: `'a: 'b` | |
48663c56 XL |
60 | |
61 | error: aborting due to 4 previous errors | |
62 |