Skip to content

Commit dd8d2f1

Browse files
steveklabnikManishearth
authored andcommitted
Clear up the reference around let
First, re-word the section on if let/while let to be more clear. Second, actually call them let statements in the statement section Fixes rust-lang#29801
1 parent ab88658 commit dd8d2f1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

reference.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,9 +2415,9 @@ in meaning to declaring the item outside the statement block.
24152415
> **Note**: there is no implicit capture of the function's dynamic environment when
24162416
> declaring a function-local item.
24172417
2418-
#### Variable declarations
2418+
#### `let` statements
24192419

2420-
A _variable declaration_ introduces a new set of variable, given by a pattern. The
2420+
A _`let` statement_ introduces a new set of variables, given by a pattern. The
24212421
pattern may be followed by a type annotation, and/or an initializer expression.
24222422
When no type annotation is given, the compiler will infer the type, or signal
24232423
an error if insufficient type information is available for definite inference.
@@ -3190,10 +3190,11 @@ let message = match maybe_digit {
31903190

31913191
### `if let` expressions
31923192

3193-
An `if let` expression is semantically identical to an `if` expression but in place
3194-
of a condition expression it expects a refutable let statement. If the value of the
3195-
expression on the right hand side of the let statement matches the pattern, the corresponding
3196-
block will execute, otherwise flow proceeds to the first `else` block that follows.
3193+
An `if let` expression is semantically identical to an `if` expression but in
3194+
place of a condition expression it expects a `let` statement with a refutable
3195+
pattern. If the value of the expression on the right hand side of the `let`
3196+
statement matches the pattern, the corresponding block will execute, otherwise
3197+
flow proceeds to the first `else` block that follows.
31973198

31983199
```
31993200
let dish = ("Ham", "Eggs");
@@ -3211,11 +3212,11 @@ if let ("Ham", b) = dish {
32113212

32123213
### `while let` loops
32133214

3214-
A `while let` loop is semantically identical to a `while` loop but in place of a
3215-
condition expression it expects a refutable let statement. If the value of the
3216-
expression on the right hand side of the let statement matches the pattern, the
3217-
loop body block executes and control returns to the pattern matching statement.
3218-
Otherwise, the while expression completes.
3215+
A `while let` loop is semantically identical to a `while` loop but in place of
3216+
a condition expression it expects `let` statement with a refutable pattern. If
3217+
the value of the expression on the right hand side of the `let` statement
3218+
matches the pattern, the loop body block executes and control returns to the
3219+
pattern matching statement. Otherwise, the while expression completes.
32193220

32203221
### `return` expressions
32213222

0 commit comments

Comments
 (0)