Skip to content

Commit ecb2dd1

Browse files
committed
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 (rust-lang#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>`.
1 parent 5962aa9 commit ecb2dd1

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/parse/parser.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::token::TokenKind;
55
use rustc_ast::{ast, attr, ptr};
66
use rustc_errors::Diag;
77
use rustc_parse::parser::Parser as RawParser;
8-
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
8+
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
99
use rustc_span::{sym, Span};
1010
use thin_vec::ThinVec;
1111

@@ -51,12 +51,9 @@ impl<'a> ParserBuilder<'a> {
5151

5252
let parser = match Self::parser(psess.inner(), input) {
5353
Ok(p) => p,
54-
Err(db) => {
55-
if let Some(diagnostics) = db {
56-
psess.emit_diagnostics(diagnostics);
57-
return Err(ParserError::ParserCreationError);
58-
}
59-
return Err(ParserError::ParsePanicError);
54+
Err(diagnostics) => {
55+
psess.emit_diagnostics(diagnostics);
56+
return Err(ParserError::ParserCreationError);
6057
}
6158
};
6259

@@ -66,18 +63,14 @@ impl<'a> ParserBuilder<'a> {
6663
fn parser(
6764
psess: &'a rustc_session::parse::ParseSess,
6865
input: Input,
69-
) -> Result<rustc_parse::parser::Parser<'a>, Option<Vec<Diag<'a>>>> {
66+
) -> Result<RawParser<'a>, Vec<Diag<'a>>> {
7067
match input {
71-
Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || {
72-
unwrap_or_emit_fatal(new_parser_from_file(psess, file, None))
73-
}))
74-
.map_err(|_| None),
75-
Input::Text(text) => rustc_parse::new_parser_from_source_str(
68+
Input::File(ref file) => new_parser_from_file(psess, file, None),
69+
Input::Text(text) => new_parser_from_source_str(
7670
psess,
7771
rustc_span::FileName::Custom("stdin".to_owned()),
7872
text,
79-
)
80-
.map_err(Some),
73+
),
8174
}
8275
}
8376
}

0 commit comments

Comments
 (0)