Skip to content

Commit aadf994

Browse files
committed
Uninterpolate literal to use as field index
1 parent e2ba9d1 commit aadf994

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/rustc_ast/src/token.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,9 @@ impl Token {
452452
}
453453

454454
// A convenience function for matching on identifiers during parsing.
455-
// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token
456-
// into the regular identifier or lifetime token it refers to,
455+
// Turns interpolated identifier ($i:ident), lifetime ($l:lifetime), and
456+
// integer literal ($l:literal) into the regular identifier or lifetime or
457+
// literal token it refers to,
457458
// otherwise returns the original token.
458459
pub fn uninterpolate(&self) -> Cow<'_, Token> {
459460
match &self.kind {
@@ -462,6 +463,11 @@ impl Token {
462463
Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span))
463464
}
464465
NtLifetime(ident) => Cow::Owned(Token::new(Lifetime(ident.name), ident.span)),
466+
NtLiteral(ref literal)
467+
if let ast::ExprKind::Lit(ast::Lit { token, kind: ast::LitKind::Int(..), .. }) = literal.kind =>
468+
{
469+
Cow::Owned(Token::new(Literal(token), literal.span))
470+
}
465471
_ => Cow::Borrowed(self),
466472
},
467473
_ => Cow::Borrowed(self),

0 commit comments

Comments
 (0)