Skip to content
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

handle recoverable submod parse errors correctly #4200

Merged
merged 1 commit into from
May 25, 2020

Conversation

calebcartwright
Copy link
Member

Fixes #4126

@@ -0,0 +1,6 @@
fn foo() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I elected to stash the test files in a new directory under tests (parser) since they're explicitly testing for fatal errors during formatting as opposed to our typical integration/idempotence tests.

I'm open to another directory name and/or location, but I do think it's important to have negative scenario tests like this to help give us better protection against upstream changes in rustc parsing and prevent any regressions.

sess.reset_errors();
if sess.can_reset_errors() {
sess.reset_errors();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this (and the similar change in parse_mod_items below) could cause any unintended side effects.

The only use case I could think of would be an instance where rustfmt is seeing, and deliberately swallowing, a parser error that the rustc parser was unable to recover from. Since this parsing logic is running on all submods now that the rustc parser doesn't parse out-of-line mods, I went ahead and changed this as I can't think of any reason why we would want to ignore such parsing errors.

@calebcartwright
Copy link
Member Author

TravisCI failure is spurious and unrelated and has been popping up on several PR's lately

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@karyon
Copy link
Contributor

karyon commented Oct 27, 2021

backported in #4253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustfmt deletes lines instead of detecting a syntax error
3 participants