1
Fork 0

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.
This commit is contained in:
Nicholas Nethercote 2024-01-05 09:55:07 +11:00
parent 6682f243dc
commit 1881055000

View file

@ -1212,29 +1212,32 @@ impl<'a> Parser<'a> {
match x { match x {
Ok((_, _, false)) => { Ok((_, _, false)) => {
if self.eat(&token::Gt) { if self.eat(&token::Gt) {
// We made sense of it. Improve the error message.
e.span_suggestion_verbose( e.span_suggestion_verbose(
binop.span.shrink_to_lo(), binop.span.shrink_to_lo(),
fluent::parse_sugg_turbofish_syntax, fluent::parse_sugg_turbofish_syntax,
"::", "::",
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
) );
.emit_without_consuming();
match self.parse_expr() { match self.parse_expr() {
Ok(_) => { 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)); *expr = self.mk_expr_err(expr.span.to(self.prev_token.span));
return Ok(()); return Ok(());
} }
Err(err) => { Err(err) => {
*expr = self.mk_expr_err(expr.span);
err.cancel(); err.cancel();
} }
} }
} }
} }
Ok((_, _, true)) => {}
Err(err) => { Err(err) => {
err.cancel(); err.cancel();
} }
_ => {}
} }
} }
Err(e) Err(e)