diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2025-05-28 10:28:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-28 10:28:11 -0400 |
| commit | d6b1108cdae286fb680f310bc5929924bdf25965 (patch) | |
| tree | 356b35d66c40a5b81363c3670db5d60b02e41c06 /compiler/rustc_parse/src | |
| parent | 97f6e6e8ba92d760bdb6591794ba905711a54a65 (diff) | |
| parent | adcd0bf5c36ee49acf390f0d75125da4efda35ac (diff) | |
| download | rust-d6b1108cdae286fb680f310bc5929924bdf25965.tar.gz rust-d6b1108cdae286fb680f310bc5929924bdf25965.zip | |
Rollup merge of #141670 - chenyukang:yukang-fix-ice-from-contracts, r=nnethercote
Fix ICE in tokenstream with contracts from parser recovery
Fixes rust-lang/rust#140683
After two times of parsing error, the `recover_stmt_` constructs an error ast, then when we expand macors, the invalid tokenstream triggered ICE because of mismatched delims.
Expected `{` and get other tokens is an obvious error message, too much effort on recovery may introduce noise.
r? ```@nnethercote```
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 396ded96bde..ccc3410674b 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -515,8 +515,8 @@ impl<'a> Parser<'a> { fn error_block_no_opening_brace_msg(&mut self, msg: Cow<'static, str>) -> Diag<'a> { let prev = self.prev_token.span; let sp = self.token.span; - let mut e = self.dcx().struct_span_err(sp, msg); - self.label_expected_raw_ref(&mut e); + let mut err = self.dcx().struct_span_err(sp, msg); + self.label_expected_raw_ref(&mut err); let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon @@ -558,20 +558,19 @@ impl<'a> Parser<'a> { stmt.span }; self.suggest_fixes_misparsed_for_loop_head( - &mut e, + &mut err, prev.between(sp), stmt_span, &stmt.kind, ); } Err(e) => { - self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore); - e.cancel(); + e.delay_as_bug(); } _ => {} } - e.span_label(sp, "expected `{`"); - e + err.span_label(sp, "expected `{`"); + err } fn suggest_fixes_misparsed_for_loop_head( |
