Open
Description
Error E0301 "the parameter type T
may not live long enough" could explain where the lifetime requirement comes from.
Here's some example code where the T: 'static
requirement comes implicitly from a Box<Trait>
trait object (so 'static is invisible).
trait Funny { }
fn new_funny_handle<T: Funny + Default>() -> Box<Funny> {
Box::new(T::default())
}
error: the parameter type `T` may not live long enough [--explain E0310]
--> <anon>:5:5
5 |> Box::new(T::default())
|> ^^^^^^^^^^^^^^^^^^^^^^
help: consider adding an explicit lifetime bound `T: 'static`...
note: ...so that the type `T` will meet its required lifetime bounds
--> <anon>:5:5
5 |> Box::new(T::default())
|>