1
Fork 0

Remove a Span from TokenKind::Interpolated.

This span records the declaration of the metavariable in the LHS of the macro.
It's used in a couple of error messages. Unfortunately, it gets in the way of
the long-term goal of removing `TokenKind::Interpolated`. So this commit
removes it, which degrades a couple of (obscure) error messages but makes
things simpler and enables the next commit.
This commit is contained in:
Nicholas Nethercote 2024-04-22 16:29:27 +10:00
parent 852a78ea8d
commit 9a63a42cb7
19 changed files with 62 additions and 97 deletions

View file

@ -490,14 +490,14 @@ impl TokenStream {
fn flatten_token(token: &Token, spacing: Spacing) -> TokenTree {
match &token.kind {
token::Interpolated(nt) if let token::NtIdent(ident, is_raw) = nt.0 => {
TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span), spacing)
token::Interpolated(nt) if let token::NtIdent(ident, is_raw) = &**nt => {
TokenTree::Token(Token::new(token::Ident(ident.name, *is_raw), ident.span), spacing)
}
token::Interpolated(nt) => TokenTree::Delimited(
DelimSpan::from_single(token.span),
DelimSpacing::new(Spacing::JointHidden, spacing),
Delimiter::Invisible,
TokenStream::from_nonterminal_ast(&nt.0).flattened(),
TokenStream::from_nonterminal_ast(&nt).flattened(),
),
_ => TokenTree::Token(token.clone(), spacing),
}