Skip to content

Commit 6b6d2a0

Browse files
authored
Merge pull request #1189 from mattheww/2022-04_bools
Boolean literal expressions
2 parents 60e99b1 + 9c5c3cb commit 6b6d2a0

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/expressions/literal-expr.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
>    | [RAW_BYTE_STRING_LITERAL]\
1111
>    | [INTEGER_LITERAL][^out-of-range]\
1212
>    | [FLOAT_LITERAL]\
13-
>    | [BOOLEAN_LITERAL]
13+
>    | `true` | `false`
1414
>
1515
> [^out-of-range]: A value ≥ 2<sup>128</sup> is not allowed.
1616
1717
A _literal expression_ is an expression consisting of a single token, rather than a sequence of tokens, that immediately and directly denotes the value it evaluates to, rather than referring to it by name or some other evaluation rule.
1818

1919
A literal is a form of [constant expression], so is evaluated (primarily) at compile time.
2020

21-
Each of the lexical [literal][literal tokens] forms described earlier can make up a literal expression.
21+
Each of the lexical [literal][literal tokens] forms described earlier can make up a literal expression, as can the keywords `true` and `false`.
2222

2323
```rust
2424
"hello"; // string type
@@ -148,10 +148,14 @@ The value of the expression is determined from the string representation of the
148148
149149
## Boolean literal expressions
150150

151-
A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
151+
A boolean literal expression consists of one of the keywords `true` or `false`.
152+
153+
The expression's type is the primitive [boolean type], and its value is:
154+
* true if the keyword is `true`
155+
* false if the keyword is `false`
152156

153-
> **Note**: This section is incomplete.
154157

158+
[boolean type]: ../types/boolean.md
155159
[constant expression]: ../const_eval.md#constant-expressions
156160
[floating-point types]: ../types/numeric.md#floating-point-types
157161
[lint check]: ../attributes/diagnostics.md#lint-check-attributes
@@ -176,4 +180,3 @@ A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
176180
[RAW_BYTE_STRING_LITERAL]: ../tokens.md#raw-byte-string-literals
177181
[INTEGER_LITERAL]: ../tokens.md#integer-literals
178182
[FLOAT_LITERAL]: ../tokens.md#floating-point-literals
179-
[BOOLEAN_LITERAL]: ../tokens.md#boolean-literals

src/patterns.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match
122122

123123
> **<sup>Syntax</sup>**\
124124
> _LiteralPattern_ :\
125-
> &nbsp;&nbsp; &nbsp;&nbsp; [BOOLEAN_LITERAL]\
125+
> &nbsp;&nbsp; &nbsp;&nbsp; `true` | `false`\
126126
> &nbsp;&nbsp; | [CHAR_LITERAL]\
127127
> &nbsp;&nbsp; | [BYTE_LITERAL]\
128128
> &nbsp;&nbsp; | [STRING_LITERAL]\
@@ -132,7 +132,6 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match
132132
> &nbsp;&nbsp; | `-`<sup>?</sup> [INTEGER_LITERAL]\
133133
> &nbsp;&nbsp; | `-`<sup>?</sup> [FLOAT_LITERAL]
134134
135-
[BOOLEAN_LITERAL]: tokens.md#boolean-literals
136135
[CHAR_LITERAL]: tokens.md#character-literals
137136
[BYTE_LITERAL]: tokens.md#byte-literals
138137
[STRING_LITERAL]: tokens.md#string-literals

src/tokens.md

-9
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,6 @@ Examples of reserved forms:
560560
2.0em; // this is not a pseudoliteral, or `2.0` followed by `em`
561561
```
562562

563-
### Boolean literals
564-
565-
> **<sup>Lexer</sup>**\
566-
> BOOLEAN_LITERAL :\
567-
> &nbsp;&nbsp; &nbsp;&nbsp; `true`\
568-
> &nbsp;&nbsp; | `false`
569-
570-
The two values of the boolean type are written `true` and `false`.
571-
572563
## Lifetimes and loop labels
573564

574565
> **<sup>Lexer</sup>**\

0 commit comments

Comments
 (0)