diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-05 10:42:31 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-08 16:01:22 +1100 |
| commit | 3ce34f42e160d7e63132c7e3994861bb876eb943 (patch) | |
| tree | f7dde69064555f1ede42e902f57d294e5cc64f8b /compiler/rustc_parse/src/parser/diagnostics.rs | |
| parent | 1881055000485527e3ad69e2bc6c9fa247e3f06f (diff) | |
| download | rust-3ce34f42e160d7e63132c7e3994861bb876eb943.tar.gz rust-3ce34f42e160d7e63132c7e3994861bb876eb943.zip | |
Remove a second `DiagnosticBuilder::emit_without_consuming` call.
Instead of taking `seq` as a mutable reference, `maybe_recover_struct_lit_bad_delims` now consumes `seq` on the recovery path, and returns `seq` unchanged on the non-recovery path. The commit also combines an `if` and a `match` to merge two identical paths. Also change `recover_seq_parse_error` so it receives a `PErr` instead of a `PResult`, because all the call sites now handle the `Ok`/`Err` distinction themselves.
Diffstat (limited to 'compiler/rustc_parse/src/parser/diagnostics.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index b05940f3569..776d0ace875 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -35,7 +35,7 @@ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ pluralize, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, FatalError, - PResult, + PErr, PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -2044,17 +2044,12 @@ impl<'a> Parser<'a> { &mut self, delim: Delimiter, lo: Span, - result: PResult<'a, P<Expr>>, + err: PErr<'a>, ) -> P<Expr> { - match result { - Ok(x) => x, - Err(err) => { - err.emit(); - // Recover from parse error, callers expect the closing delim to be consumed. - self.consume_block(delim, ConsumeClosingDelim::Yes); - self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err) - } - } + err.emit(); + // Recover from parse error, callers expect the closing delim to be consumed. + self.consume_block(delim, ConsumeClosingDelim::Yes); + self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err) } /// Eats tokens until we can be relatively sure we reached the end of the |
