LitKind in rustc_ast::ast - Rust (original) (raw)
pub enum LitKind {
Str(Symbol, StrStyle),
ByteStr(Arc<[u8]>, StrStyle),
CStr(Arc<[u8]>, StrStyle),
Byte(u8),
Char(char),
Int(Pu128, LitIntType),
Float(Symbol, LitFloatType),
Bool(bool),
Err(ErrorGuaranteed),
}
Expand description
This type is used within both ast::MetaItemLit
and hir::Lit
.
Note that the entire literal (including the suffix) is considered when deciding the LitKind
. This means that float literals like 1f32
are classified by this type as Float
. This is different to token::LitKind
which does not consider the suffix.
A string literal ("foo"
). The symbol is unescaped, and so may differ from the original token’s symbol.
A byte string (b"foo"
). Not stored as a symbol because it might be non-utf8, and symbols only allow utf8 strings.
A C String (c"foo"
). Guaranteed to only have \0
at the end.
A byte char (b'f'
).
A character literal ('a'
).
An integer literal (1
).
A float literal (1.0
, 1f64
or 1E10f64
). The pre-suffix part is stored as a symbol rather than f64
so that LitKind
can impl Eq
and Hash
.
A boolean literal (true
, false
).
Placeholder for a literal that wasn’t well-formed in some way.
Converts literal token into a semantic literal.
Returns true
if this literal is a string.
Returns true
if this literal is byte literal string.
Returns true
if this is a numeric literal.
Returns true
if this literal has no suffix. Note: this will return true for literals with prefixes such as raw strings and byte strings.
Returns true
if this literal has a suffix.
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: 24 bytes
Size for each variant:
Str
: 7 bytesByteStr
: 23 bytesCStr
: 23 bytesByte
: 1 byteChar
: 7 bytesInt
: 23 bytesFloat
: 7 bytesBool
: 1 byteErr
: 0 bytes