diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-08-21 18:28:47 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-09-10 17:33:06 -0400 |
| commit | d5a04a9927d1685d63f1d59039ea7dd03ee090a5 (patch) | |
| tree | da8065d7902f5574fdb42636439ce4101ff87ea1 /compiler/rustc_parse/src/parser | |
| parent | 1823dea7df9e125022dfda8126b6713f142f0e73 (diff) | |
| download | rust-d5a04a9927d1685d63f1d59039ea7dd03ee090a5.tar.gz rust-d5a04a9927d1685d63f1d59039ea7dd03ee090a5.zip | |
Collect tokens when handling `:literal` matcher
An `NtLiteral` just wraps an `Expr`, so we don't need to add a new `tokens` field to an AST struct.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index d70fa532850..516c2c77213 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -140,7 +140,15 @@ impl<'a> Parser<'a> { } token::NtExpr(expr) } - NonterminalKind::Literal => token::NtLiteral(self.parse_literal_maybe_minus()?), + NonterminalKind::Literal => { + let (mut lit, tokens) = + self.collect_tokens(|this| this.parse_literal_maybe_minus())?; + // We have have eaten a nonterminal, which could already have tokens + if lit.tokens.is_none() { + lit.tokens = Some(tokens); + } + token::NtLiteral(lit) + } NonterminalKind::Ty => { let (mut ty, tokens) = self.collect_tokens(|this| this.parse_ty())?; // We have an eaten an NtTy, which could already have tokens |
