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

Resolve some minor parsing bugs #4439

Merged
merged 2 commits into from
Oct 7, 2020

Conversation

calebcartwright
Copy link
Member

This address a couple minor parsing bugs, notably an uncaught rustc parser panic that was only triggered with certain inputs in the main/root file, some poor rustfmt parsing error message, and a spurious parser diagnostic cancel instead of emission.

Fixes #4418
Fixes #4431

Comment on lines +83 to +94
) -> Result<rustc_parse::parser::Parser<'a>, Option<Vec<Diagnostic>>> {
match input {
Input::File(ref file) => Ok(new_parser_from_file(sess, file, None)),
Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || {
new_parser_from_file(sess, file, None)
}))
.map_err(|_| None),
Input::Text(text) => rustc_parse::maybe_new_parser_from_source_str(
sess,
rustc_span::FileName::Custom("stdin".to_owned()),
text,
),
)
.map_err(|db| Some(db)),
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 terribly thrilled about Option-wrapping the error diagnostics to address this, but since new_parser_from_file doesn't return a Result and will instead panic this seemed like the least invasive/intensive way to resolve the bug

@@ -118,7 +118,7 @@ pub enum OperationError {
#[error("invalid glob pattern found in ignore list: {0}")]
InvalidGlobPattern(ignore::Error),
/// Parse error occurred while parsing the input.
#[error("failed to parse {input:?}")]
#[error("failed to parse {input}")]
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the failed to parse Real("...") error detail that was reported in the linked issue to instead display the correct error (e.g. failed to parse /home/caleb/dev/rustfmt-sandbox/bad-syntax/src/openbrace.rs and failed to parse <stdin> for stdin)

@calebcartwright
Copy link
Member Author

Going to go ahead and merge as the changes are pretty trivial and can always be refactored should a better solution present itself 😄

@calebcartwright calebcartwright merged commit 19e3caa into rust-lang:master Oct 7, 2020
@calebcartwright calebcartwright deleted the parsing-fixes branch October 7, 2020 01:28
@topecongiro
Copy link
Contributor

Apologies for the late review; all the changes look good to me. Thank you!

@karyon
Copy link
Contributor

karyon commented Oct 26, 2021

backported in #4503

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.

Error writing files: failed to resolve mod on missing semicolon failed to parse Real("...")
3 participants