The following program
不编译:
use std::any::Any;
trait Foo<'a> {
fn to_box_any(self: Box<Self>) -> Box<Any + 'a>;
}
fn test<'a>(v: Box<dyn Foo<'a> + 'a>) {
v.to_box_any();
}
fn main() {}
错误消息:
error[E0478]: lifetime bound not satisfied
--> src/main.rs:8:7
|
8 | v.to_box_any();
| ^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime 'a as defined on the function body at 7:1
--> src/main.rs:7:1
|
7 | fn test<'a>(v: Box<dyn Foo<'a> + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: but lifetime parameter must outlive the static lifetime
我想我已经尽可能多的标记了明确的生命时间,但是我不知道
static
寿命要求来自。
如果我改变
Any
它有一个定制的特性,所以看起来像
任何
正在创建需求?