Skip to content

Commit

Permalink
fix ice in suggesting
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed May 8, 2023
1 parent 20e6e6a commit a7fc32c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 14 additions & 7 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/type/missing-let-in-binding-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct A {
: :u8, //~ ERROR expected identifier, found `:`
}

fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/type/missing-let-in-binding-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: expected identifier, found `:`
--> $DIR/missing-let-in-binding-3.rs:2:5
|
LL | struct A {
| - while parsing this struct
LL | : :u8,
| ^ expected identifier

error: aborting due to previous error

0 comments on commit a7fc32c

Please sign in to comment.