From e06b267eeb7bed90605dd63f6cae585674e0b1f5 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Thu, 7 Apr 2022 20:14:04 +0100 Subject: [PATCH 1/2] Stop defining a separate BOOLEAN_LITERAL token `true` and `false` are already listed as keywords. --- src/expressions/literal-expr.md | 7 +++---- src/patterns.md | 3 +-- src/tokens.md | 9 --------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/expressions/literal-expr.md b/src/expressions/literal-expr.md index 82363b70a..5f00d0b1a 100644 --- a/src/expressions/literal-expr.md +++ b/src/expressions/literal-expr.md @@ -10,7 +10,7 @@ >    | [RAW_BYTE_STRING_LITERAL]\ >    | [INTEGER_LITERAL][^out-of-range]\ >    | [FLOAT_LITERAL]\ ->    | [BOOLEAN_LITERAL] +>    | `true` | `false` > > [^out-of-range]: A value ≥ 2128 is not allowed. @@ -18,7 +18,7 @@ A _literal expression_ is an expression consisting of a single token, rather tha 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 @@ -148,7 +148,7 @@ 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`. > **Note**: This section is incomplete. @@ -176,4 +176,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 diff --git a/src/patterns.md b/src/patterns.md index e13f198bc..91b8a7f48 100644 --- a/src/patterns.md +++ b/src/patterns.md @@ -122,7 +122,7 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match > **Syntax**\ > _LiteralPattern_ :\ ->       [BOOLEAN_LITERAL]\ +>       `true` | `false`\ >    | [CHAR_LITERAL]\ >    | [BYTE_LITERAL]\ >    | [STRING_LITERAL]\ @@ -132,7 +132,6 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match >    | `-`? [INTEGER_LITERAL]\ >    | `-`? [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 diff --git a/src/tokens.md b/src/tokens.md index 589d9eaa5..cdb4f07f7 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -560,15 +560,6 @@ Examples of reserved forms: 2.0em; // this is not a pseudoliteral, or `2.0` followed by `em` ``` -### Boolean literals - -> **Lexer**\ -> BOOLEAN_LITERAL :\ ->       `true`\ ->    | `false` - -The two values of the boolean type are written `true` and `false`. - ## Lifetimes and loop labels > **Lexer**\ From 9c5c3cb9d160787f31903e61abd2ba4567182b5c Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Thu, 7 Apr 2022 20:15:03 +0100 Subject: [PATCH 2/2] Document boolean literal expressions --- src/expressions/literal-expr.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/expressions/literal-expr.md b/src/expressions/literal-expr.md index 5f00d0b1a..4eec37dcb 100644 --- a/src/expressions/literal-expr.md +++ b/src/expressions/literal-expr.md @@ -150,8 +150,12 @@ The value of the expression is determined from the string representation of the A boolean literal expression consists of one of the keywords `true` or `false`. -> **Note**: This section is incomplete. +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` + +[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