Skip to content

Commit 3c885ad

Browse files
committed
Separate sections for range/slice pattern capturing
The rules for the capturing behavior related to range patterns and slice patterns were comingled with the rules for capturing and discriminant reads. While these are spiritually related, they are distinct, so let's break these apart into separate sections.
1 parent 151b109 commit 3c885ad

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/types/closure.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ let _ = &mut x; // ERROR: Cannot borrow `x` as mutable.
353353
c();
354354
```
355355

356-
r[type.closure.capture.precision.discriminants.range-patterns]
356+
357+
r[type.closure.capture.precision.range-patterns]
358+
### Capturing and range patterns
359+
360+
r[type.closure.capture.precision.range-patterns.reads]
357361
Matching against a [range pattern][patterns.range] reads the place being matched, even if the range includes all possible values of the type, and captures the place by `ImmBorrow`.
358362

359363
```rust,compile_fail,E0502
@@ -365,7 +369,10 @@ let _ = &mut x; // ERROR: Cannot borrow `x` as mutable.
365369
c();
366370
```
367371

368-
r[type.closure.capture.precision.discriminants.slice-patterns-slices]
372+
r[type.closure.capture.precision.slice-patterns]
373+
### Capturing and slice patterns
374+
375+
r[type.closure.capture.precision.slice-patterns.slices]
369376
Matching a slice against a [slice pattern][patterns.slice] other than one with only a single [rest pattern][patterns.rest] (i.e. `[..]`) reads the length from the wide pointer and captures the pointer's place by `ImmBorrow`.
370377

371378
```rust,compile_fail,E0502
@@ -392,7 +399,7 @@ x; // OK: `x` can be moved here.
392399
c();
393400
```
394401

395-
r[type.closure.capture.precision.discriminants.slice-patterns-arrays]
402+
r[type.closure.capture.precision.slice-patterns.arrays]
396403
As the length of an array is fixed by its type, matching an array against a slice pattern does not by itself capture the place.
397404

398405
```rust,no_run

0 commit comments

Comments
 (0)