-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Reduce spurious errors when parsing malformed list #45074
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
//~| NOTE: no resolution found | ||
//~| ERROR: unresolved function `bar` | ||
//~| NOTE: no resolution found | ||
//~| ERROR: expected one of `)`, `,`, `.`, `<`, `?` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change highlights that error recovery in the parser no longer works in some cases (that's the purpose of this test indeed!).
So the effect of this patch is that it disables error recovery for one particular randomly selected function parse_unspanned_seq
.
Yes, this happens to improve diagnostics for the example from #44339, but I don't think this is an acceptable solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would do is to introduce the notion of "similar separators" (e.g. ,
and .
from #44339 which are close to each other on a keyboard) and accept separators "similar" to the desired one in parse_seq_to_before_tokens
after issuing a non-fatal error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I understand. Yes it makes sense to try harder to consume the rest of the sequence before we return. Okay I will explore this option. That will be a different solution so I'll close this PR. Thanks for the feedback!
Fixes #44339 (both cases) where you get extra errors beyond the main cause with input like
use std::{foo. bar};
While parsing this there is a stack of calls like this:
An error occurs in (2), which is emitted and swallowed in (1). Then at the bottom in
parse_item_()
we end up emitting an unneeded second error:What I propose is to make (1) and (2) return a new structure that contains the
Vec<T>
and anOption<DiagnosticBuilder>
. This way, the callers who don't mind can easily take theVec<T>
to continue the old behaviour, whileparse_unspanned_seq
can instead propagate the error in its PResult.