about summary refs log tree commit diff
path: root/src/parse
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-06-03 14:32:03 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-06-05 10:38:03 +1000
commitecb2dd151c4d78fa9231f66e9c90dfef90dab4cc (patch)
tree1348f2ceca1ceb7e9fe2611bb0712942c3af62be /src/parse
parent5962aa96f1aad5c30e19119c6da0ea19e0588ea5 (diff)
downloadrust-ecb2dd151c4d78fa9231f66e9c90dfef90dab4cc.tar.gz
rust-ecb2dd151c4d78fa9231f66e9c90dfef90dab4cc.zip
rustfmt: Remove an unnecessary `catch_unwind` use.
The `Input::File` and `Input::Text` cases should be very similar.
However, currently the `Input::File` case uses `catch_unwind` because,
until recently (#125815) there was a fallible version of
`new_parser_from_source_str` but only an infallible version of
`new_parser_from_file`. This difference wasn't fundamental, just an
overlooked gap in the API of `rustc_parse`.

Both of those operations are now fallible, so the `Input::File` and
`Input::Text` cases can made more similar, with no need for
`catch_unwind`. This also lets us simplify an `Option<Vec<Diag>>` to
`Vec<Diag>`.
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/parser.rs23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 7adf339b453..6051241309d 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -5,7 +5,7 @@ use rustc_ast::token::TokenKind;
 use rustc_ast::{ast, attr, ptr};
 use rustc_errors::Diag;
 use rustc_parse::parser::Parser as RawParser;
-use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
+use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
 use rustc_span::{sym, Span};
 use thin_vec::ThinVec;
 
@@ -51,12 +51,9 @@ impl<'a> ParserBuilder<'a> {
 
         let parser = match Self::parser(psess.inner(), input) {
             Ok(p) => p,
-            Err(db) => {
-                if let Some(diagnostics) = db {
-                    psess.emit_diagnostics(diagnostics);
-                    return Err(ParserError::ParserCreationError);
-                }
-                return Err(ParserError::ParsePanicError);
+            Err(diagnostics) => {
+                psess.emit_diagnostics(diagnostics);
+                return Err(ParserError::ParserCreationError);
             }
         };
 
@@ -66,18 +63,14 @@ impl<'a> ParserBuilder<'a> {
     fn parser(
         psess: &'a rustc_session::parse::ParseSess,
         input: Input,
-    ) -> Result<rustc_parse::parser::Parser<'a>, Option<Vec<Diag<'a>>>> {
+    ) -> Result<RawParser<'a>, Vec<Diag<'a>>> {
         match input {
-            Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || {
-                unwrap_or_emit_fatal(new_parser_from_file(psess, file, None))
-            }))
-            .map_err(|_| None),
-            Input::Text(text) => rustc_parse::new_parser_from_source_str(
+            Input::File(ref file) => new_parser_from_file(psess, file, None),
+            Input::Text(text) => new_parser_from_source_str(
                 psess,
                 rustc_span::FileName::Custom("stdin".to_owned()),
                 text,
-            )
-            .map_err(Some),
+            ),
         }
     }
 }