mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #3806
3806: lower bool literal value r=flodiebold a=JoshMcguigan Following up on #3805, this PR adds the literal value to `ast::LiteralKind` so when we lower we can use the actual value from the source code rather than the default value for the type. Ultimately I plan to use this for exhaustiveness checking in #3706. I didn't include this in the previous PR because I wasn't sure if it made sense to add this information to `ast::LiteralKind` or provide some other mechanism to get this from `ast::Literal`. For now I've only implemented this for boolean literals, but I think it could be easily extended to other types. A possible exception to this are string literals, since we may not want to clone around an owned string to hold onto in `ast::LiteralKind`, and it'd be nice to avoid adding a generic lifetime as well. Perhaps we won't ever care about the actual value of a string literal? Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
This commit is contained in:
commit
0a41412ced
2 changed files with 4 additions and 3 deletions
|
@ -748,7 +748,7 @@ impl From<ast::LiteralKind> for Literal {
|
|||
LiteralKind::ByteString => Literal::ByteString(Default::default()),
|
||||
LiteralKind::String => Literal::String(Default::default()),
|
||||
LiteralKind::Byte => Literal::Int(Default::default(), Some(BuiltinInt::U8)),
|
||||
LiteralKind::Bool => Literal::Bool(Default::default()),
|
||||
LiteralKind::Bool(val) => Literal::Bool(val),
|
||||
LiteralKind::Char => Literal::Char(Default::default()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ pub enum LiteralKind {
|
|||
Byte,
|
||||
IntNumber { suffix: Option<SmolStr> },
|
||||
FloatNumber { suffix: Option<SmolStr> },
|
||||
Bool,
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
impl ast::Literal {
|
||||
|
@ -355,7 +355,8 @@ impl ast::Literal {
|
|||
LiteralKind::FloatNumber { suffix: Self::find_suffix(&text, &FLOAT_SUFFIXES) }
|
||||
}
|
||||
STRING | RAW_STRING => LiteralKind::String,
|
||||
T![true] | T![false] => LiteralKind::Bool,
|
||||
T![true] => LiteralKind::Bool(true),
|
||||
T![false] => LiteralKind::Bool(false),
|
||||
BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString,
|
||||
CHAR => LiteralKind::Char,
|
||||
BYTE => LiteralKind::Byte,
|
||||
|
|
Loading…
Reference in a new issue