-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix fn front matter parsing ICE from invalid code. #60132
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
This commit fixes an "unreachable code" ICE that results from parsing invalid code where the compiler is expecting the next trait item declaration in the middle of the previous trait item due to extra closing braces.
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.
I would like us to handle this more gracefully but this PR is good. r=me unless you want to address the comment in this PR.
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't | ||
// account for this. | ||
if !self.expect_one_of(&[], &[])? { unreachable!() } | ||
} |
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.
Although I think this change will fix the general problem today, I feel we could also address the side of the recovery code as well to not attempt to close the block when encountering an incorrect closing delimiter. It is tricky because what is best to do depends entirely on the type of mistake made and we don't do global analysis...
What do you think? Should we have a follow up PR/ticket with different common cases to test the recovery mechanism?
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.
I’d land this as is to fix the ICE, but I think a follow up to try and handle this case more gracefully definitely makes sense.
I spent a bunch of time trying to work out a nice way to recover from this case but I couldn’t see one. If we don’t attempt to close the block when encountering an unclosed delimiter then that’ll regress other cases that we recover from currently, it’s a tough one.
@bors r+ rollup |
📌 Commit 60c6ed9 has been approved by |
Fix fn front matter parsing ICE from invalid code. Fixes #60075. This PR fixes an "unreachable code" ICE that results from parsing invalid code where the compiler is expecting the next trait item declaration in the middle of the previous trait item due to extra closing braces. r? @estebank (thanks for the minimized test case)
☀️ Test successful - checks-travis, status-appveyor |
Fixes #60075.
This PR fixes an "unreachable code" ICE that results from parsing
invalid code where the compiler is expecting the next trait item
declaration in the middle of the previous trait item due to extra
closing braces.
r? @estebank (thanks for the minimized test case)