From 71b055152f70d6e21a75b0ddc7f5d383accdea38 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Wed, 4 Mar 2020 01:32:21 +0100 Subject: [PATCH 1/2] Add information about || and && to Grammar describing `while let`. Also fix italics to be consistent with other pages. --- src/expressions/loop-expr.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index e37235a30..d1cbc636c 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -45,7 +45,7 @@ have type compatible with the value of the `break` expression(s). > **Syntax**\ > _PredicateLoopExpression_ :\ ->    `while` [_Expression_]except struct expression [_BlockExpression_] +>    `while` [_Expression_]_except struct expression_ [_BlockExpression_] A `while` loop begins by evaluating the boolean loop conditional expression. If the loop conditional expression evaluates to `true`, the loop body block @@ -67,7 +67,7 @@ while i < 10 { > **Syntax**\ > [_PredicatePatternLoopExpression_] :\ ->    `while` `let` [_MatchArmPatterns_] `=` [_Expression_]except struct expression +>    `while` `let` [_MatchArmPatterns_] `=` [_Expression_]_except struct or lazy boolean operator expression_ > [_BlockExpression_] A `while let` loop is semantically similar to a `while` loop but in place of a @@ -123,11 +123,32 @@ while let Some(v @ 1) | Some(v @ 2) = vals.pop() { } ``` +The expression cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_]. +Use of a lazy boolean operator is ambiguous with a planned feature change +of the language (the implementation of if-let chains - see [eRFC 2947][_eRFCIfLetChain_]). +When lazy boolean operator expression is desired, this can be achieved +by using parenthesis as below: + + +```rust,ignore +// Before... +while let PAT = EXPR && EXPR { .. } + +// After... +while let PAT = ( EXPR && EXPR ) { .. } + +// Before... +while let PAT = EXPR || EXPR { .. } + +// After... +while let PAT = ( EXPR || EXPR ) { .. } +``` + ## Iterator loops > **Syntax**\ > _IteratorLoopExpression_ :\ ->    `for` [_Pattern_] `in` [_Expression_]except struct expression +>    `for` [_Pattern_] `in` [_Expression_]_except struct expression_ > [_BlockExpression_] A `for` expression is a syntactic construct for looping over elements provided From 532060a3f2fcdef49afbe9e2c6f97d0fb61410b7 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Wed, 4 Mar 2020 20:00:56 +0100 Subject: [PATCH 2/2] Remove duplicated explanation about lazy boolean operators in while let, refer to the if let page instead. --- src/expressions/loop-expr.md | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index d1cbc636c..3bff9adaf 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -123,26 +123,7 @@ while let Some(v @ 1) | Some(v @ 2) = vals.pop() { } ``` -The expression cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_]. -Use of a lazy boolean operator is ambiguous with a planned feature change -of the language (the implementation of if-let chains - see [eRFC 2947][_eRFCIfLetChain_]). -When lazy boolean operator expression is desired, this can be achieved -by using parenthesis as below: - - -```rust,ignore -// Before... -while let PAT = EXPR && EXPR { .. } - -// After... -while let PAT = ( EXPR && EXPR ) { .. } - -// Before... -while let PAT = EXPR || EXPR { .. } - -// After... -while let PAT = ( EXPR || EXPR ) { .. } -``` +As is the case in [`if let` expressions], the scrutinee cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_]. ## Iterator loops @@ -315,3 +296,5 @@ expression `()`. [`match` expression]: match-expr.md [scrutinee]: ../glossary.md#scrutinee [temporary values]: ../expressions.md#temporary-lifetimes +[_LazyBooleanOperatorExpression_]: operator-expr.md#lazy-boolean-operators +[`if let` expressions]: if-expr.md#if-let-expressions