about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-05-08 11:16:17 +0800
committeryukang <moorekang@gmail.com>2023-05-08 11:16:17 +0800
commita7fc32ceaf4708a26a992f61c4ac4ead1555c8eb (patch)
treee3a76ce24226fc2a5ed7111901d270b30ee6cda6 /compiler/rustc_parse/src
parent20e6e6a4932991c4b53605154868cfa645b04998 (diff)
downloadrust-a7fc32ceaf4708a26a992f61c4ac4ead1555c8eb.tar.gz
rust-a7fc32ceaf4708a26a992f61c4ac4ead1555c8eb.zip
fix ice in suggesting
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index bd0ea50b4d8..456c6243bbb 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -405,13 +405,20 @@ impl<'a> Parser<'a> {
             let prev_span = self.prev_token.span.shrink_to_lo();
             let snapshot = self.create_snapshot_for_diagnostic();
             self.bump();
-            if self.parse_ty().is_ok() && self.token == token::Eq {
-                err.span_suggestion_verbose(
-                    prev_span,
-                    "you might have meant to introduce a new binding",
-                    "let ".to_string(),
-                    Applicability::MaybeIncorrect,
-                );
+            match self.parse_ty() {
+                Ok(_) => {
+                    if self.token == token::Eq {
+                        err.span_suggestion_verbose(
+                            prev_span,
+                            "you might have meant to introduce a new binding",
+                            "let ".to_string(),
+                            Applicability::MaybeIncorrect,
+                        );
+                    }
+                }
+                Err(err) => {
+                    err.cancel();
+                }
             }
             self.restore_snapshot(snapshot);
         }