diff options
| author | Yutaro Ohno <yutaro.ono.418@gmail.com> | 2022-12-03 23:24:49 +0900 |
|---|---|---|
| committer | Yutaro Ohno <yutaro.ono.418@gmail.com> | 2022-12-03 23:24:49 +0900 |
| commit | 690addc6ecc575f6b9df5e2fc09bd119e51e6194 (patch) | |
| tree | 6e702c8533816a72e47d81386a0f369398b6927f /compiler | |
| parent | 703d95e183fbb678249d8f61cabc732e46884e00 (diff) | |
| download | rust-690addc6ecc575f6b9df5e2fc09bd119e51e6194.tar.gz rust-690addc6ecc575f6b9df5e2fc09bd119e51e6194.zip | |
parser: fix ICE with invalid variable declaration in macro call
Fix ICE on parsing an invalid variable declaration as a statement like:
```
macro_rules! m { ($s:stmt) => {} }
m! { var x }
```
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index ff1ddfd97df..b4813250547 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -72,12 +72,12 @@ impl<'a> Parser<'a> { Ok(Some(if self.token.is_keyword(kw::Let) { self.parse_local_mk(lo, attrs, capture_semi, force_collect)? - } else if self.is_kw_followed_by_ident(kw::Mut) { + } else if self.is_kw_followed_by_ident(kw::Mut) && self.may_recover() { self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::MissingLet)? - } else if self.is_kw_followed_by_ident(kw::Auto) { + } else if self.is_kw_followed_by_ident(kw::Auto) && self.may_recover() { self.bump(); // `auto` self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::UseLetNotAuto)? - } else if self.is_kw_followed_by_ident(sym::var) { + } else if self.is_kw_followed_by_ident(sym::var) && self.may_recover() { self.bump(); // `var` self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::UseLetNotVar)? } else if self.check_path() && !self.token.is_qpath_start() && !self.is_path_start_item() { @@ -244,7 +244,7 @@ impl<'a> Parser<'a> { } fn recover_local_after_let(&mut self, lo: Span, attrs: AttrWrapper) -> PResult<'a, Stmt> { - self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| { + self.collect_tokens_trailing_token(attrs, ForceCollect::Yes, |this, attrs| { let local = this.parse_local(attrs)?; // FIXME - maybe capture semicolon in recovery? Ok(( |
