1
Fork 0

Rollup merge of #100909 - nnethercote:minor-ast-LitKind-improvement, r=petrochenkov

Minor `ast::LitKind` improvements

r? `@petrochenkov`
This commit is contained in:
Dylan DPC 2022-08-23 20:40:09 +05:30 committed by GitHub
commit 28ead17745
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 21 additions and 21 deletions

View file

@ -1751,7 +1751,8 @@ pub enum LitFloatType {
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)]
pub enum LitKind {
/// A string literal (`"foo"`).
/// A string literal (`"foo"`). The symbol is unescaped, and so may differ
/// from the original token's symbol.
Str(Symbol, StrStyle),
/// A byte string (`b"foo"`).
ByteStr(Lrc<[u8]>),
@ -1761,12 +1762,13 @@ pub enum LitKind {
Char(char),
/// An integer literal (`1`).
Int(u128, LitIntType),
/// A float literal (`1f64` or `1E10f64`).
/// A float literal (`1f64` or `1E10f64`). Stored as a symbol rather than
/// `f64` so that `LitKind` can impl `Eq` and `Hash`.
Float(Symbol, LitFloatType),
/// A boolean literal.
Bool(bool),
/// Placeholder for a literal that wasn't well-formed in some way.
Err(Symbol),
Err,
}
impl LitKind {
@ -1805,7 +1807,7 @@ impl LitKind {
| LitKind::Int(_, LitIntType::Unsuffixed)
| LitKind::Float(_, LitFloatType::Unsuffixed)
| LitKind::Bool(..)
| LitKind::Err(..) => false,
| LitKind::Err => false,
}
}
}

View file

@ -146,7 +146,7 @@ impl LitKind {
LitKind::ByteStr(bytes.into())
}
token::Err => LitKind::Err(symbol),
token::Err => LitKind::Err,
})
}
@ -199,7 +199,7 @@ impl LitKind {
let symbol = if value { kw::True } else { kw::False };
(token::Bool, symbol, None)
}
LitKind::Err(symbol) => (token::Err, symbol, None),
LitKind::Err => unreachable!(),
};
token::Lit::new(kind, symbol, suffix)