Spacing in rustc_ast::tokenstream - Rust (original) (raw)
pub enum Spacing {
Alone,
Joint,
JointHidden,
}Expand description
Indicates whether a token can join with the following token to form a compound token. Used for conversions to proc_macro::Spacing. Also used to guide pretty-printing, which is where the JointHidden value (which isn’t part of proc_macro::Spacing) comes in useful.
The token cannot join with the following token to form a compound token.
In token streams parsed from source code, the compiler will use Alonefor any token immediately followed by whitespace, a non-doc comment, or EOF.
When constructing token streams within the compiler, use this for each token that (a) should be pretty-printed with a space after it, or (b) is the last token in the stream. (In the latter case the choice of spacing doesn’t matter because it is never used for the last token. We arbitrarily use Alone.)
Converts to proc_macro::Spacing::Alone, andproc_macro::Spacing::Alone converts back to this.
The token can join with the following token to form a compound token.
In token streams parsed from source code, the compiler will use Jointfor any token immediately followed by punctuation (as determined byToken::is_punct).
When constructing token streams within the compiler, use this for each token that (a) should be pretty-printed without a space after it, and (b) is followed by a punctuation token.
Converts to proc_macro::Spacing::Joint, andproc_macro::Spacing::Joint converts back to this.
The token can join with the following token to form a compound token, but this will not be visible at the proc macro level. (This is what theHidden means; see below.)
In token streams parsed from source code, the compiler will useJointHidden for any token immediately followed by anything not covered by the Alone and Joint cases: an identifier, lifetime, literal, delimiter, doc comment.
When constructing token streams, use this for each token that (a) should be pretty-printed without a space after it, and (b) is followed by a non-punctuation token.
Converts to proc_macro::Spacing::Alone, butproc_macro::Spacing::Alone converts back to token::Spacing::Alone. Because of that, pretty-printing of TokenStreams produced by proc macros is unavoidably uglier (with more whitespace between tokens) than pretty-printing of TokenStream’s produced by other means (i.e. parsed source code, internally constructed token streams, and token streams produced by declarative macros).
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: 1 byte
Size for each variant:
Alone: 0 bytesJoint: 0 bytesJointHidden: 0 bytes