E0195 diagnostic should take into account GATs, etc #135350
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
Context: #109476 and #87803. Those are filed as bugs, so I'm filing this diagnostic issue separately. It's plausible this will become moot if those issues are resolved, but it's not certain that will happen (or that it will happen soon).
When I encountered this, it took me awhile to figure out that E0195 was really about late-vs-early lifetimes parameters. Only when I figured that out did the error make sense. Late-vs-early lifetime parameters are niche knowledge, so I'm not entirely sure how to phrase the error message; it needs to probably spell out a workaround, as it's not obvious.
The current phrasing of E0195 makes sense when lifetime parameters are early bound due to appearing in explicit bounds. However, lifetime parameters can also become early bound implicitly/invisibly, such as in the example. There are similar cases (see #87803) when the return type is an RPIT/RPITIT (
-> impl Trait
) -- in which case the lifetime is early bound due to appearing in the implicituse<..>
bounds.Also in those cases, exactly matching the signature from the trait is not always an option or desirable. For example, when using refinement and/or precise capturing -- i.e. intentionally removing a lifetime from the return type in order to provide more functionality than the trait requires.
So for example while
-> Self::Gat<'_>
would be a usable suggestion for the code at the top of this issue, it is not a usable suggestion here:Other cases
Being explicit about lifetimes doesn't improve things; the span highlighted has an "Expected
X
foundX
" flavor.Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: