-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve diagnostics for impl Trait capturing lifetimes #78402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The error is correct, I think. You happen to call foo with a static value, but you don't put that in the type signature, so someone else is free to call it with a shorter lifetime. If you want to enforce only static lifetimes for foo, you can use |
Oh wait, I missed that the return type of bar doesn't (or at least, shouldn't) depends on a. Yeah this does seem like a bug then. |
As cramertj wrote there, the current behavior is by design of the RPIT RFC ("Assumption 2"), because it was expected that |
Based on the RFC I think it's correct that this wouldn't compile. However, I am curious why adding a
That ought to remove any doubt that the return type is tied to the lifetime of Also, this still fails to compile when
|
@tmandry from #42940 (comment)
(emphasis mine) So when adding an explicit lifetime bound, it's in addition to the implicit one, not instead of. And since |
Current output:
|
I tried this code:
I expected to see this happen: compiles correctly.
Instead, this happened:
Meta
rustc 1.47.0. This appears to be #42940, fixing which might depend on
type-alias-impl-trait
(although so far that's only a workaround, not really a fix?). It would be nice to have more specific diagnostics here.The text was updated successfully, but these errors were encountered: