Skip to content

Commit c2bdf38

Browse files
Fairer examples
1 parent b078485 commit c2bdf38

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

text/3627-match-ergonomics-2024.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ anyway is that the current behavior is unintuitive and surprising for users.
334334

335335
```rust
336336
//! All editions: works only with this rule
337-
let &[[a]] = &[&mut [42]]; // x: &i32
337+
let &(i, j, [s]) = &(63, 42, &mut [String::from("🦀")]); // i: i32, j: i32, s: &String
338338
```
339339

340340
```rust
341341
//! All editions: works with or without this rule (alternative to above)
342-
// Note the explicit `ref`, we must abandon match ergonomics
343-
let &[[ref a]] = &[&mut [42]]; // x: &i32
344-
let &[&mut [ref a]] = &[&mut [42]]; // x: &i32
342+
let (&i, &j, [s]) = &(42, &mut [String::from("🦀")]); // i: i32, j: i32, s: &String
343+
let &(i, j, [ref s]) = &(42, &mut [String::from("🦀")]); // i: i32, j: i32, s: &String
344+
let &(i, j, &mut [ref s]) = &(42, &mut [String::from("🦀")]); // i: i32, j: i32, s: &String
345345
```
346346

347347
#### Patterns that work only without this rule
@@ -356,7 +356,6 @@ let &[[&mut a]] = &[&mut [42]]; // x: i32
356356

357357
```rust
358358
//! Edition ≥ 2024: works with or without this rule (alternatives to above)
359-
// No need to abandon match ergonomics
360359
let &[[&a]] = &[&mut [42]]; // x: i32
361360
let &[&mut [a]] = &[&mut [42]]; // x: i32
362361
```
@@ -468,8 +467,8 @@ concerns with certain proposals for "deref patterns".
468467
[future-possibilities]: #future-possibilities
469468

470469
- An explicit syntax for mutable by-reference bindings should be chosen at some
471-
point, along with removing the prohibition on implicitly by-reference
472-
mutable bindings.
470+
point, along with removing the prohibition on implicitly by-reference mutable
471+
bindings.
473472
- Future changes to reference types (partial borrows, language sugar for `Pin`,
474473
etc) may interact with match ergonomics.
475474

@@ -484,8 +483,7 @@ question that would need to be resolved is whether and how deref patterns
484483
## Matching `&mut` behind `&`
485484

486485
There is one notable situation where match ergonomics cannot be used, and
487-
explicit `ref` is required. Notably, this can occur where `&mut` is nested
488-
behind `&`:
486+
explicit `ref` is required. This happens where `&mut` is nested behind `&`:
489487

490488
```rust
491489
// No way to avoid the `ref`, even with this RFC

0 commit comments

Comments
 (0)