Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean literal expressions #1189

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/expressions/literal-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
>    | [RAW_BYTE_STRING_LITERAL]\
>    | [INTEGER_LITERAL][^out-of-range]\
>    | [FLOAT_LITERAL]\
>    | [BOOLEAN_LITERAL]
>    | `true` | `false`
>
> [^out-of-range]: A value ≥ 2<sup>128</sup> is not allowed.

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.

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

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

```rust
"hello"; // string type
Expand Down Expand Up @@ -148,10 +148,14 @@ The value of the expression is determined from the string representation of the

## Boolean literal expressions

A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
A boolean literal expression consists of one of the keywords `true` or `false`.

The expression's type is the primitive [boolean type], and its value is:
* true if the keyword is `true`
* false if the keyword is `false`

> **Note**: This section is incomplete.

[boolean type]: ../types/boolean.md
[constant expression]: ../const_eval.md#constant-expressions
[floating-point types]: ../types/numeric.md#floating-point-types
[lint check]: ../attributes/diagnostics.md#lint-check-attributes
Expand All @@ -176,4 +180,3 @@ A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
[RAW_BYTE_STRING_LITERAL]: ../tokens.md#raw-byte-string-literals
[INTEGER_LITERAL]: ../tokens.md#integer-literals
[FLOAT_LITERAL]: ../tokens.md#floating-point-literals
[BOOLEAN_LITERAL]: ../tokens.md#boolean-literals
3 changes: 1 addition & 2 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match

> **<sup>Syntax</sup>**\
> _LiteralPattern_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; [BOOLEAN_LITERAL]\
> &nbsp;&nbsp; &nbsp;&nbsp; `true` | `false`\
> &nbsp;&nbsp; | [CHAR_LITERAL]\
> &nbsp;&nbsp; | [BYTE_LITERAL]\
> &nbsp;&nbsp; | [STRING_LITERAL]\
Expand All @@ -132,7 +132,6 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match
> &nbsp;&nbsp; | `-`<sup>?</sup> [INTEGER_LITERAL]\
> &nbsp;&nbsp; | `-`<sup>?</sup> [FLOAT_LITERAL]

[BOOLEAN_LITERAL]: tokens.md#boolean-literals
[CHAR_LITERAL]: tokens.md#character-literals
[BYTE_LITERAL]: tokens.md#byte-literals
[STRING_LITERAL]: tokens.md#string-literals
Expand Down
9 changes: 0 additions & 9 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,6 @@ Examples of reserved forms:
2.0em; // this is not a pseudoliteral, or `2.0` followed by `em`
```

### Boolean literals

> **<sup>Lexer</sup>**\
> BOOLEAN_LITERAL :\
> &nbsp;&nbsp; &nbsp;&nbsp; `true`\
> &nbsp;&nbsp; | `false`

The two values of the boolean type are written `true` and `false`.

## Lifetimes and loop labels

> **<sup>Lexer</sup>**\
Expand Down