Closed
Description
I tried this code:
trait Trait {}
impl Trait for () {}
fn get_trait<I>() -> impl Trait + 'static {
()
}
fn assert_static<A: 'static>(_: A) {}
fn test<T>(_: T) {
assert_static(get_trait::<T>());
}
I expected that rustc
will compile this code. But it doesn't. Instead, I've got this error:
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:11:5
|
10 | fn test<T>(_: T) {
| - help: consider adding an explicit lifetime bound...: `T: 'static`
11 | assert_static(get_trait::<T>());
| ^^^^^^^^^^^^^ ...so that the type `impl Trait` will meet its required lifetime bounds
The error seems weird because the return type of get_trait
is explicitly marked as 'static
and T
/I
is not used anywhere at all.
This may be related to #49431 though I'm not entirely sure.
Meta
Checked on 1.46.0
stable and 1.48.0-nightly
(2020-09-17 f3c923a)