f5bae722be
Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`. ``` error[E0478]: lifetime bound not satisfied --> f202.rs:2:12 | 2 | value: Box<dyn std::any::Any + 'a>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> f202.rs:1:14 | 1 | struct Hello<'a> { | ^^ note: but lifetime parameter must outlive the static lifetime --> /home/gh-estebank/rust/library/core/src/any.rs:113:16 | 113 | pub trait Any: 'static { | ^^^^^^^ ``` Partially address #33652.
14 lines
294 B
Rust
14 lines
294 B
Rust
struct Hello<'a> {
|
|
value: Box<dyn std::any::Any + 'a>,
|
|
//~^ ERROR lifetime bound not satisfied
|
|
}
|
|
|
|
impl<'a> Hello<'a> {
|
|
fn new<T: 'a>(value: T) -> Self {
|
|
Self { value: Box::new(value) }
|
|
//~^ ERROR the parameter type `T` may not live long enough
|
|
}
|
|
}
|
|
|
|
fn main() {}
|