Improve syntax error for misplaced lifetime quantifier (for<'a>
) outside of APIT type
#117882
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
I don't remember what the official name for
for<'a>
syntax in general is, so I've used "quantifier" in the proposed message.The main thing I'm filing the issue for is that there's a large cascade of syntax errors, none of which explain the actual problem (the leading "expected identifier" is particularly bad), and which seem to be due to poor recovery (starting to parse the rest of the type as a new function parameter, as if there was a comma); it would be nice to have more concise and more helpful output, particularly because
for<'a>
is a superficially simple "modifier" syntax that does appear in multiple places in types, just not this one.I hope that it will be simple to fix by making
for<'a>
something that is always parsed but not always permitted.Also, rust-analyzer's current diagnostic for this is significantly better just by being a basic parse error: "expected a function pointer or path". It doesn't point the user to the right fix, but it does actually mention what the non-syntax-error cases would be: a
fn
pointer with lifetimes — or a pre-2021-unmarked-dyn
(sigh).Other cases
No response
Anything else?
Occurs on stable 1.73 and 1.76.0-nightly (2023-11-12 2b603f9)
The text was updated successfully, but these errors were encountered: