You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/match-expr.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -217,9 +217,9 @@ Before a guard (including an `if let` guard) is evaluated:
217
217
}
218
218
```
219
219
2. Guard evaluation happens after that, and:
220
-
* It runs using a shared borrow of the scrutinee
221
-
* You cannot move from the scrutinee inside the guard.
222
-
* New bindings created inside the guard (e.g., via `if let Some(y) = expr`) are local to the guard and do not persist into the match arm body.
220
+
* Guard evaluation follows successful main pattern match. Variables bound by the main pattern are usable within the guard, respecting their binding type (borrow/move)
221
+
* Moves from the scrutinee in the guard are subject to standard Rust ownership rules. Avoid moving what's needed later; already moved parts from the main pattern can be used.
222
+
* Variables successfully bound within the if let guard are in scope within the corresponding match arm body. Their scope extends to the arm after the guard condition is met.
0 commit comments