Skip to content

Commit

Permalink
further improve match guard bind-by-move docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril authored Nov 30, 2019
1 parent c03b84c commit 2bb5698
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/expressions/match-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ let message = match maybe_digit {
> ```
A pattern guard may refer to the variables bound within the pattern they follow.
When such a variable's binding mode is by-value,
a shared reference is taken to it before evaluating the guard.
When accessing the variable in the guard by shared reference,
the shared reference taken before evaluating the guard is used.
Only when the guard expression evaluates to true is the by-value variable
moved, or copied, into the arm's body. This allows shared borrows to be used
Before evaluating the guard, a shared reference is taken to the part of the
scrutinee the variable matches on. While evaluating the guard,
this shared reference is then used when accessing the variable.
Only when the guard evaluates to true is the value moved, or copied,
from the scrutinee into the variable. This allows shared borrows to be used
inside guards without moving out of the scrutinee in case guard fails to match.
Moreover, by holding a shared reference while evaluating the guard,
mutation inside guards is also prevented.
## Attributes on match arms
Expand Down

0 comments on commit 2bb5698

Please sign in to comment.