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.
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
| 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.
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