-
Notifications
You must be signed in to change notification settings - Fork 898
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
Resolve some minor parsing bugs #4439
Conversation
) -> 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)), |
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'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}")] |
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 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)
Going to go ahead and merge as the changes are pretty trivial and can always be refactored should a better solution present itself 😄 |
Apologies for the late review; all the changes look good to me. Thank you! |
backported in #4503 |
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