diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-09-10 16:59:30 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-09-10 17:33:06 -0400 |
| commit | 156ef2bee8f3941d4d7e3414652b803348ccd165 (patch) | |
| tree | 31a9945d066ecafa5b22a893cf999fb77fef6181 /compiler/rustc_parse/src/parser | |
| parent | c1011165e63480dabf1913e308da8b344dfa8f8a (diff) | |
| download | rust-156ef2bee8f3941d4d7e3414652b803348ccd165.tar.gz rust-156ef2bee8f3941d4d7e3414652b803348ccd165.zip | |
Attach tokens to `ast::Stmt`
We currently only attach tokens when parsing a `:stmt` matcher for a `macro_rules!` macro. Proc-macro attributes on statements are still unstable, and need additional work.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index f98f2a89dc6..15660fd574c 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -119,10 +119,20 @@ impl<'a> Parser<'a> { } token::NtBlock(block) } - NonterminalKind::Stmt => match self.parse_stmt()? { - Some(s) => token::NtStmt(s), - None => return Err(self.struct_span_err(self.token.span, "expected a statement")), - }, + NonterminalKind::Stmt => { + let (stmt, tokens) = self.collect_tokens(|this| this.parse_stmt())?; + match stmt { + Some(mut s) => { + if s.tokens.is_none() { + s.tokens = Some(tokens); + } + token::NtStmt(s) + } + None => { + return Err(self.struct_span_err(self.token.span, "expected a statement")); + } + } + } NonterminalKind::Pat => { let (mut pat, tokens) = self.collect_tokens(|this| this.parse_pat(None))?; // We have have eaten an NtPat, which could already have tokens diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 6cc42487684..64b959e8325 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -415,7 +415,7 @@ impl<'a> Parser<'a> { } pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt { - Stmt { id: DUMMY_NODE_ID, kind, span } + Stmt { id: DUMMY_NODE_ID, kind, span, tokens: None } } fn mk_stmt_err(&self, span: Span) -> Stmt { |
