rustc could explain that dyn Trait sometimes implies 'static #83246
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lifetimes
Area: Lifetimes / regions
A-trait-system
Area: Trait system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
In the following code: (playground link)
The current output is:
The error is correct, yet I didn't write
'static
anywhere in the program. What gives? This made me scratch my head for a few minutes. As it turns out, inimpl dyn Foo
,dyn Foo
is treated as short fordyn Foo + 'static
. The issue can be fixed by changingimpl dyn Foo
toimpl<'a> dyn Foo + 'a
.I wouldn't say the current error is bad, exactly, but it would be nice if rustc could somehow warn the user about what's going on – either by warning on the impl itself, or by somehow attaching an explanation to the type error (though that might not be worth the complexity).
The text was updated successfully, but these errors were encountered: