Skip to content

Commit e9115a8

Browse files
committed
fixed if let guards documentation
1 parent 5b96f71 commit e9115a8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/expressions/match-expr.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ r[expr.match.if.let.guard]
157157
Match arms can include `if let` guards to allow conditional pattern matching within the guard clause. This feature is currently unstable and requires the attribute. It is tracked in issue [#51114](https://github.com/rust-lang/rust/issues/51114).
158158
159159
r[expr.match.if.let.guard.syntax]
160-
```rust
160+
```rust,ignore
161161
match expression {
162162
pattern if let subpattern = guard_expr => arm_body,
163163
...
@@ -170,7 +170,7 @@ When the pattern matches successfully, the `if let` expression in the guard is e
170170
* If the inner pattern (`subpattern`) matches the result of `guard_expr`, the guard evaluates to `true`.
171171
* Otherwise, the next arm is tested.
172172

173-
```rust
173+
```rust,ignore
174174
let value = Some(10);
175175
176176
let msg = match value {
@@ -184,7 +184,7 @@ r[expr.match.if.let.guard.scope]
184184
* The `if let` guard may refer to variables bound by the outer match pattern.
185185
* New variables bound inside the `if let` guard (e.g., `y` in the example above) are available within the body of the match arm where the guard evaluates to `true`, but are not accessible in other arms or outside the match expression.
186186

187-
```rust
187+
```rust,ignore
188188
let opt = Some(42);
189189
190190
match opt {
@@ -209,7 +209,7 @@ r[expr.match.if.let.guard.borrowing]
209209
Before a guard (including an `if let` guard) is evaluated:
210210
1. Pattern bindings are performed first
211211
Variables from the outer match pattern (e.g., `x` in `Some(x)`) are bound and initialized. These bindings may involve moving, copying, or borrowing values from the scrutinee.
212-
```rust
212+
```rust,ignore
213213
match Some(String::from("hello")) {
214214
Some(s) if /* guard */ => { /* s is moved here */ }
215215
_ => {}
@@ -219,7 +219,7 @@ Before a guard (including an `if let` guard) is evaluated:
219219
* It runs using a shared borrow of the scrutinee
220220
* You cannot move from the scrutinee inside the guard.
221221
* 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.
222-
```rust
222+
```rust,ignore
223223
let val = Some(vec![1, 2, 3]);
224224
225225
let result = match val {
@@ -234,7 +234,7 @@ Before a guard (including an `if let` guard) is evaluated:
234234
```
235235
> [!NOTE]
236236
> Unlike regular if guards, `if let` guards execute only once per match arm, even if the pattern uses the `|` operator to match multiple patterns. This avoids repeated evaluation and potential side effects.
237-
> ```rust
237+
> ```rust,ignore
238238
> use std::cell::Cell;
239239
>
240240
> let i: Cell<i32> = Cell::new(0);

0 commit comments

Comments
 (0)