Skip to content

Commit a7fc32c

Browse files
committed
fix ice in suggesting
1 parent 20e6e6a commit a7fc32c

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,20 @@ impl<'a> Parser<'a> {
405405
let prev_span = self.prev_token.span.shrink_to_lo();
406406
let snapshot = self.create_snapshot_for_diagnostic();
407407
self.bump();
408-
if self.parse_ty().is_ok() && self.token == token::Eq {
409-
err.span_suggestion_verbose(
410-
prev_span,
411-
"you might have meant to introduce a new binding",
412-
"let ".to_string(),
413-
Applicability::MaybeIncorrect,
414-
);
408+
match self.parse_ty() {
409+
Ok(_) => {
410+
if self.token == token::Eq {
411+
err.span_suggestion_verbose(
412+
prev_span,
413+
"you might have meant to introduce a new binding",
414+
"let ".to_string(),
415+
Applicability::MaybeIncorrect,
416+
);
417+
}
418+
}
419+
Err(err) => {
420+
err.cancel();
421+
}
415422
}
416423
self.restore_snapshot(snapshot);
417424
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct A {
2+
: :u8, //~ ERROR expected identifier, found `:`
3+
}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected identifier, found `:`
2+
--> $DIR/missing-let-in-binding-3.rs:2:5
3+
|
4+
LL | struct A {
5+
| - while parsing this struct
6+
LL | : :u8,
7+
| ^ expected identifier
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)