Skip to content

Commit

Permalink
Rollup merge of rust-lang#122115 - clubby789:cancel-recoverr, r=compi…
Browse files Browse the repository at this point in the history
…ler-errors

Cancel parsing ever made during recovery

Fixes rust-lang#122112

It would be nice if diagnostics from recovery were automatically cancelled... 🤔
  • Loading branch information
workingjubilee authored Mar 7, 2024
2 parents a88c35d + 8e45d0f commit 3a4b2c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
16 changes: 10 additions & 6 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
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 `=`
| |
| 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

0 comments on commit 3a4b2c1

Please sign in to comment.