diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-01 18:38:00 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-01 18:38:00 +0100 |
commit | 0a41412ced3784363580ddaef089605250d6398e (patch) | |
tree | ddc82aaaf8e35fa652feb04400fd31bc9af4749e /crates/ra_syntax/src/ast | |
parent | f39b51d025c080682a35706ffcb86c2aeb28044b (diff) | |
parent | d0b6b2ee2f4a447f4c3827f87ebaf5216de6f226 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 77cceb382..8bbd946c0 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -308,7 +308,7 @@ pub enum LiteralKind { | |||
308 | Byte, | 308 | Byte, |
309 | IntNumber { suffix: Option<SmolStr> }, | 309 | IntNumber { suffix: Option<SmolStr> }, |
310 | FloatNumber { suffix: Option<SmolStr> }, | 310 | FloatNumber { suffix: Option<SmolStr> }, |
311 | Bool, | 311 | Bool(bool), |
312 | } | 312 | } |
313 | 313 | ||
314 | impl ast::Literal { | 314 | impl ast::Literal { |
@@ -355,7 +355,8 @@ impl ast::Literal { | |||
355 | LiteralKind::FloatNumber { suffix: Self::find_suffix(&text, &FLOAT_SUFFIXES) } | 355 | LiteralKind::FloatNumber { suffix: Self::find_suffix(&text, &FLOAT_SUFFIXES) } |
356 | } | 356 | } |
357 | STRING | RAW_STRING => LiteralKind::String, | 357 | STRING | RAW_STRING => LiteralKind::String, |
358 | T![true] | T![false] => LiteralKind::Bool, | 358 | T![true] => LiteralKind::Bool(true), |
359 | T![false] => LiteralKind::Bool(false), | ||
359 | BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString, | 360 | BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString, |
360 | CHAR => LiteralKind::Char, | 361 | CHAR => LiteralKind::Char, |
361 | BYTE => LiteralKind::Byte, | 362 | BYTE => LiteralKind::Byte, |