Open
Description
opened on Nov 21, 2022
I tried this code:
fn check<'a, T: Trait<'a> + ?Sized>() {}
trait Trait<'a>: 'static {}
fn check2<'a>() {
check::<dyn Trait<'a> + 'static>();
}
I expected to see this happen: It compiles
dyn Trait<'a>
should have an lifetime independent from 'a
. i.e. dyn Trait<'a> + 'b
should have lifetime 'b
. in this particular case, 'b
is 'static
.
Instead, this happened:
error: lifetime may not live long enough
--> src/lib.rs:5:5
|
4 | fn check2<'a>() {
| -- lifetime `'a` defined here
5 | check::<dyn Trait<'a> + 'static>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
Related
#88904. Since this is another way of creating dyn Trait: !Trait
, except in this case, I think the unsized coercion should be allowed, and dyn Trait
does impl Trait
.
Activity