Enum rustc_ast::tokenstream::TokenTree
source · pub enum TokenTree {
Token(Token, Spacing),
Delimited(DelimSpan, Delimiter, TokenStream),
}
Expand description
When the main Rust parser encounters a syntax-extension invocation, it parses the arguments to the invocation as a token tree. This is a very loose structure, such that all sorts of different AST fragments can be passed to syntax extensions using a uniform type.
If the syntax extension is an MBE macro, it will attempt to match its
LHS token tree against the provided token tree, and if it finds a
match, will transcribe the RHS token tree, splicing in any captured
macro_parser::matched_nonterminals
into the SubstNt
s it finds.
The RHS of an MBE macro is the only place SubstNt
s are substituted.
Nothing special happens to misnamed or misplaced SubstNt
s.
Variants§
Token(Token, Spacing)
A single token.
Delimited(DelimSpan, Delimiter, TokenStream)
A delimited sequence of token trees.
Implementations§
source§impl TokenTree
impl TokenTree
sourcepub fn eq_unspanned(&self, other: &TokenTree) -> bool
pub fn eq_unspanned(&self, other: &TokenTree) -> bool
Checks if this TokenTree
is equal to the other, regardless of span information.
sourcepub fn token_alone(kind: TokenKind, span: Span) -> TokenTree
pub fn token_alone(kind: TokenKind, span: Span) -> TokenTree
Create a TokenTree::Token
with alone spacing.
sourcepub fn token_joint(kind: TokenKind, span: Span) -> TokenTree
pub fn token_joint(kind: TokenKind, span: Span) -> TokenTree
Create a TokenTree::Token
with joint spacing.
pub fn uninterpolate(self) -> TokenTree
Trait Implementations§
source§impl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
source§impl<__CTX> HashStable<__CTX> for TokenTreewhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for TokenTreewhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
impl StructuralPartialEq for TokenTree
Auto Trait Implementations§
impl !RefUnwindSafe for TokenTree
impl !Send for TokenTree
impl !Sync for TokenTree
impl Unpin for TokenTree
impl !UnwindSafe for TokenTree
Blanket Implementations§
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes
Size for each variant:
Token
: 31 bytesDelimited
: 31 bytes