diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-08-21 17:52:52 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-09-10 17:33:05 -0400 |
| commit | de4bd9f0f8aeb4b89e55ba33b755c9a93e999e1c (patch) | |
| tree | 05cc6034e654ed16e2c7c7dfc5e6f8999b1a2223 /compiler/rustc_parse/src/parser | |
| parent | ad3a6f70ac9457173aa1f3f3af372aadec915f8d (diff) | |
| download | rust-de4bd9f0f8aeb4b89e55ba33b755c9a93e999e1c.tar.gz rust-de4bd9f0f8aeb4b89e55ba33b755c9a93e999e1c.zip | |
Attach `TokenStream` to `ast::Block`
A `Block` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index f40cd1131d2..47ed98b8599 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -111,7 +111,14 @@ impl<'a> Parser<'a> { return Err(self.struct_span_err(self.token.span, "expected an item keyword")); } }, - NonterminalKind::Block => token::NtBlock(self.parse_block()?), + NonterminalKind::Block => { + let (mut block, tokens) = self.collect_tokens(|this| this.parse_block())?; + // We have have eaten an NtBlock, which could already have tokens + if block.tokens.is_none() { + block.tokens = Some(tokens); + } + 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")), diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 947ca6b5bd5..6cc42487684 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -411,7 +411,7 @@ impl<'a> Parser<'a> { } pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> { - P(Block { stmts, id: DUMMY_NODE_ID, rules, span }) + P(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None }) } pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt { |
