Rollup merge of #122115 - clubby789:cancel-recoverr, r=compiler-errors

Cancel parsing ever made during recovery

Fixes #122112

It would be nice if diagnostics from recovery were automatically cancelled... 🤔
This commit is contained in:
Guillaume Gomez 2024-03-07 15:07:08 +01:00 committed by GitHub
commit 9bda4e47c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 8 deletions

View File

@ -787,13 +787,17 @@ impl<'a> Parser<'a> {
let suggest_eq = if self.token.kind == token::Dot
&& let _ = self.bump()
&& let mut snapshot = self.create_snapshot_for_diagnostic()
&& let Ok(_) = snapshot.parse_dot_suffix_expr(
colon_sp,
self.mk_expr_err(
&& let Ok(_) = snapshot
.parse_dot_suffix_expr(
colon_sp,
self.dcx().delayed_bug("error during `:` -> `=` recovery"),
),
) {
self.mk_expr_err(
colon_sp,
self.dcx()
.delayed_bug("error during `:` -> `=` recovery"),
),
)
.map_err(Diag::cancel)
{
true
} else if let Some(op) = self.check_assoc_op()
&& op.node.can_continue_expr_unambiguously()

View File

@ -1,3 +1,10 @@
#![allow(unused)]
fn test_122112() {
// Make sure we don't ICE if parsing in recovery fails
let _: std::env::temp_dir().join(&self, push: Box<usize>); //~ ERROR expected one of
}
fn main() {
let _: std::env::temp_dir().join("foo"); //~ ERROR expected one of
}

View File

@ -1,5 +1,13 @@
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
--> $DIR/recover-colon-instead-of-eq-in-local.rs:2:32
--> $DIR/recover-colon-instead-of-eq-in-local.rs:5:32
|
LL | let _: std::env::temp_dir().join(&self, push: Box<usize>);
| - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
| |
| while parsing the type for `_`
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
--> $DIR/recover-colon-instead-of-eq-in-local.rs:9:32
|
LL | let _: std::env::temp_dir().join("foo");
| - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
@ -7,5 +15,5 @@ LL | let _: std::env::temp_dir().join("foo");
| while parsing the type for `_`
| help: use `=` if you meant to assign
error: aborting due to 1 previous error
error: aborting due to 2 previous errors