diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-04-18 20:18:13 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-04-02 16:07:02 +1100 |
| commit | bb495d6d3e6dae294f08162097bd85f904e9f90b (patch) | |
| tree | 3c2779808f664b964e1c1a8c2dde2cfcb62b8328 /compiler/rustc_ast/src/tokenstream.rs | |
| parent | 70dab5a27c03a5637cc1d4ba36a5139760d25e38 (diff) | |
| download | rust-bb495d6d3e6dae294f08162097bd85f904e9f90b.tar.gz rust-bb495d6d3e6dae294f08162097bd85f904e9f90b.zip | |
Remove `NtBlock`, `Nonterminal`, and `TokenKind::Interpolated`.
`NtBlock` is the last remaining variant of `Nonterminal`, so once it is gone then `Nonterminal` can be removed as well.
Diffstat (limited to 'compiler/rustc_ast/src/tokenstream.rs')
| -rw-r--r-- | compiler/rustc_ast/src/tokenstream.rs | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index fb331e74aeb..3b457303cac 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -25,7 +25,7 @@ use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym}; use crate::ast::AttrStyle; use crate::ast_traits::{HasAttrs, HasTokens}; -use crate::token::{self, Delimiter, InvisibleOrigin, Nonterminal, Token, TokenKind}; +use crate::token::{self, Delimiter, InvisibleOrigin, Token, TokenKind}; use crate::{AttrVec, Attribute}; /// Part of a `TokenStream`. @@ -305,11 +305,6 @@ pub struct AttrsTarget { } /// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s. -/// -/// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s -/// instead of a representation of the abstract syntax tree. -/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for -/// backwards compatibility. #[derive(Clone, Debug, Default, Encodable, Decodable)] pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>); @@ -476,12 +471,6 @@ impl TokenStream { TokenStream::new(tts) } - pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream { - match nt { - Nonterminal::NtBlock(block) => TokenStream::from_ast(block), - } - } - fn flatten_token(token: &Token, spacing: Spacing) -> TokenTree { match token.kind { token::NtIdent(ident, is_raw) => { @@ -493,12 +482,6 @@ impl TokenStream { Delimiter::Invisible(InvisibleOrigin::FlattenToken), TokenStream::token_alone(token::Lifetime(ident.name, is_raw), ident.span), ), - token::Interpolated(ref nt) => TokenTree::Delimited( - DelimSpan::from_single(token.span), - DelimSpacing::new(Spacing::JointHidden, spacing), - Delimiter::Invisible(InvisibleOrigin::FlattenToken), - TokenStream::from_nonterminal_ast(&nt).flattened(), - ), _ => TokenTree::Token(token.clone(), spacing), } } @@ -516,10 +499,9 @@ impl TokenStream { pub fn flattened(&self) -> TokenStream { fn can_skip(stream: &TokenStream) -> bool { stream.iter().all(|tree| match tree { - TokenTree::Token(token, _) => !matches!( - token.kind, - token::NtIdent(..) | token::NtLifetime(..) | token::Interpolated(..) - ), + TokenTree::Token(token, _) => { + !matches!(token.kind, token::NtIdent(..) | token::NtLifetime(..)) + } TokenTree::Delimited(.., inner) => can_skip(inner), }) } |
