Skip to content

Commit c1ccd64

Browse files
authored
Merge pull request #2032 from cramertj/march-ergo-summary
Clear up match ergonomics summary
2 parents 5c1619c + 491e0af commit c1ccd64

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

text/2005-match-ergonomics.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88

99
Better ergonomics for pattern-matching on references.
1010

11-
Currently:
11+
Currently, matching on references requires a bit of a dance using
12+
`ref` and `&` patterns:
1213

1314
```
15+
let x: &Option<_> = &Some(0);
16+
17+
match x {
18+
&Some(ref y) => { ... },
19+
&None => { ... },
20+
}
21+
22+
// or using `*`:
23+
1424
match *x {
15-
Foo(ref x) => { ... }
16-
Bar(ref mut y, z) => { ... }
25+
Some(ref x) => { ... },
26+
None => { ... },
1727
}
1828
```
1929

20-
Proposed:
30+
After this RFC, the above form still works, but now we also allow a simpler form:
2131

2232
```
33+
let x: &Option<_> = &Some(0);
34+
2335
match x {
24-
Foo(x) => { ... }
25-
Bar(y, z) => { ... }
36+
Some(y) => { ... }, // `y` is a reference to `0`
37+
None => { ... },
2638
}
2739
```
2840

0 commit comments

Comments
 (0)