From 11b950a580f62f3d73c8e1440475a588b4402962 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 28 Aug 2019 22:06:41 -0400 Subject: [PATCH] Specify pattern types in `let` statements and `for` expressions Specify that the patterns in `let` statements and `for` expressions must be irrefutable. --- src/expressions/loop-expr.md | 6 +++--- src/statements.md | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/expressions/loop-expr.md b/src/expressions/loop-expr.md index d95445c43..1e73082af 100644 --- a/src/expressions/loop-expr.md +++ b/src/expressions/loop-expr.md @@ -130,9 +130,9 @@ while let Some(v @ 1) | Some(v @ 2) = vals.pop() { A `for` expression is a syntactic construct for looping over elements provided by an implementation of `std::iter::IntoIterator`. If the iterator yields a -value, that value is given the specified name and the body of the loop is -executed, then control returns to the head of the `for` loop. If the iterator -is empty, the `for` expression completes. +value, that value is matched against the irrefutable pattern, the body of the +loop is executed, and then control returns to the head of the `for` loop. If the +iterator is empty, the `for` expression completes. An example of a `for` loop over the contents of an array: diff --git a/src/statements.md b/src/statements.md index c55f00298..9b5bd94f1 100644 --- a/src/statements.md +++ b/src/statements.md @@ -56,13 +56,13 @@ fn outer() { >    [_OuterAttribute_]\* `let` [_Pattern_] > ( `:` [_Type_] )? (`=` [_Expression_] )? `;` -A *`let` statement* introduces a new set of [variables], given by a [pattern]. The -pattern is followed optionally by a type annotation and then optionally by an -initializer expression. When no type annotation is given, the compiler will -infer the type, or signal an error if insufficient type information is -available for definite inference. Any variables introduced by a variable -declaration are visible from the point of declaration until the end of the -enclosing block scope. +A *`let` statement* introduces a new set of [variables], given by an +irrefutable [pattern]. The pattern is followed optionally by a type +annotation and then optionally by an initializer expression. When no +type annotation is given, the compiler will infer the type, or signal +an error if insufficient type information is available for definite +inference. Any variables introduced by a variable declaration are visible +from the point of declaration until the end of the enclosing block scope. ## Expression statements