Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d5a04a9

Browse files
committed
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.
1 parent 1823dea commit d5a04a9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
278278
Some(tokenstream::TokenTree::token(token::Lifetime(ident.name), ident.span).into())
279279
}
280280
Nonterminal::NtTT(ref tt) => Some(tt.clone().into()),
281-
Nonterminal::NtExpr(ref expr) => {
281+
Nonterminal::NtExpr(ref expr) | Nonterminal::NtLiteral(ref expr) => {
282282
if expr.tokens.is_none() {
283283
debug!("missing tokens for expr {:?}", expr);
284284
}

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ impl<'a> Parser<'a> {
140140
}
141141
token::NtExpr(expr)
142142
}
143-
NonterminalKind::Literal => token::NtLiteral(self.parse_literal_maybe_minus()?),
143+
NonterminalKind::Literal => {
144+
let (mut lit, tokens) =
145+
self.collect_tokens(|this| this.parse_literal_maybe_minus())?;
146+
// We have have eaten a nonterminal, which could already have tokens
147+
if lit.tokens.is_none() {
148+
lit.tokens = Some(tokens);
149+
}
150+
token::NtLiteral(lit)
151+
}
144152
NonterminalKind::Ty => {
145153
let (mut ty, tokens) = self.collect_tokens(|this| this.parse_ty())?;
146154
// We have an eaten an NtTy, which could already have tokens

0 commit comments

Comments
 (0)