Open
Description
openedon 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
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: Lifetimes / regionsArea: Lifetimes / regionsArea: trait objects, vtable layoutArea: trait objects, vtable layoutCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.Relevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.