Skip to content

Commit 2bb5698

Browse files
authored
further improve match guard bind-by-move docs
1 parent c03b84c commit 2bb5698

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/expressions/match-expr.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ let message = match maybe_digit {
127127
> ```
128128
129129
A pattern guard may refer to the variables bound within the pattern they follow.
130-
When such a variable's binding mode is by-value,
131-
a shared reference is taken to it before evaluating the guard.
132-
When accessing the variable in the guard by shared reference,
133-
the shared reference taken before evaluating the guard is used.
134-
Only when the guard expression evaluates to true is the by-value variable
135-
moved, or copied, into the arm's body. This allows shared borrows to be used
130+
Before evaluating the guard, a shared reference is taken to the part of the
131+
scrutinee the variable matches on. While evaluating the guard,
132+
this shared reference is then used when accessing the variable.
133+
Only when the guard evaluates to true is the value moved, or copied,
134+
from the scrutinee into the variable. This allows shared borrows to be used
136135
inside guards without moving out of the scrutinee in case guard fails to match.
136+
Moreover, by holding a shared reference while evaluating the guard,
137+
mutation inside guards is also prevented.
137138
138139
## Attributes on match arms
139140

0 commit comments

Comments
 (0)