Skip to content

Commit 2a5adf3

Browse files
committed
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.
1 parent 8dd3576 commit 2a5adf3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,29 +1212,32 @@ impl<'a> Parser<'a> {
12121212
match x {
12131213
Ok((_, _, false)) => {
12141214
if self.eat(&token::Gt) {
1215+
// We made sense of it. Improve the error message.
12151216
e.span_suggestion_verbose(
12161217
binop.span.shrink_to_lo(),
12171218
fluent::parse_sugg_turbofish_syntax,
12181219
"::",
12191220
Applicability::MaybeIncorrect,
1220-
)
1221-
.emit_without_consuming();
1221+
);
12221222
match self.parse_expr() {
12231223
Ok(_) => {
1224+
// The subsequent expression is valid. Mark
1225+
// `expr` as erroneous and emit `e` now, but
1226+
// return `Ok` so parsing can continue.
1227+
e.emit();
12241228
*expr = self.mk_expr_err(expr.span.to(self.prev_token.span));
12251229
return Ok(());
12261230
}
12271231
Err(err) => {
1228-
*expr = self.mk_expr_err(expr.span);
12291232
err.cancel();
12301233
}
12311234
}
12321235
}
12331236
}
1237+
Ok((_, _, true)) => {}
12341238
Err(err) => {
12351239
err.cancel();
12361240
}
1237-
_ => {}
12381241
}
12391242
}
12401243
Err(e)

0 commit comments

Comments
 (0)