diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-05 09:55:07 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-01-08 16:01:22 +1100 |
| commit | 1881055000485527e3ad69e2bc6c9fa247e3f06f (patch) | |
| tree | 28821d8f181d705ed40aa9b2855b03104427ea66 | |
| parent | 6682f243dcb9babd67525bbf9798dca302f60588 (diff) | |
| download | rust-1881055000485527e3ad69e2bc6c9fa247e3f06f.tar.gz rust-1881055000485527e3ad69e2bc6c9fa247e3f06f.zip | |
Remove a `DiagnosticBuilder::emit_without_consuming` call.
In this parsing recovery function, we only need to emit the previously obtained error message and mark `expr` as erroneous in the case where we actually recover.
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 66d80fa3c52..b05940f3569 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1212,29 +1212,32 @@ impl<'a> Parser<'a> { match x { Ok((_, _, false)) => { if self.eat(&token::Gt) { + // We made sense of it. Improve the error message. e.span_suggestion_verbose( binop.span.shrink_to_lo(), fluent::parse_sugg_turbofish_syntax, "::", Applicability::MaybeIncorrect, - ) - .emit_without_consuming(); + ); match self.parse_expr() { Ok(_) => { + // The subsequent expression is valid. Mark + // `expr` as erroneous and emit `e` now, but + // return `Ok` so parsing can continue. + e.emit(); *expr = self.mk_expr_err(expr.span.to(self.prev_token.span)); return Ok(()); } Err(err) => { - *expr = self.mk_expr_err(expr.span); err.cancel(); } } } } + Ok((_, _, true)) => {} Err(err) => { err.cancel(); } - _ => {} } } Err(e) |
