-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See the [RFC] and [tracking issue]. [tracking issue]: #42640 [RFC]: https://github.com/rust-lang/rfcs/blob/491e0af/text/2005-match-ergonomics.md
- Loading branch information
Showing
46 changed files
with
1,406 additions
and
75 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/doc/unstable-book/src/language-features/match_default_bindings.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# `match_default_bindings` | ||
|
||
The tracking issue for this feature is: [#42640] | ||
|
||
[#42640]: https://github.com/rust-lang/rust/issues/42640 | ||
|
||
------------------------ | ||
|
||
Match default bindings (also called "default binding modes in match") improves ergonomics for | ||
pattern-matching on references by introducing automatic dereferencing (and a corresponding shift | ||
in binding modes) for large classes of patterns that would otherwise not compile. | ||
|
||
For example, under match default bindings, | ||
|
||
```rust | ||
#![feature(match_default_bindings)] | ||
|
||
fn main() { | ||
let x: &Option<_> = &Some(0); | ||
|
||
match x { | ||
Some(y) => { | ||
println!("y={}", *y); | ||
}, | ||
None => {}, | ||
} | ||
} | ||
``` | ||
|
||
compiles and is equivalent to either of the below: | ||
|
||
```rust | ||
fn main() { | ||
let x: &Option<_> = &Some(0); | ||
|
||
match *x { | ||
Some(ref y) => { | ||
println!("y={}", *y); | ||
}, | ||
None => {}, | ||
} | ||
} | ||
``` | ||
|
||
or | ||
|
||
```rust | ||
fn main() { | ||
let x: &Option<_> = &Some(0); | ||
|
||
match x { | ||
&Some(ref y) => { | ||
println!("y={}", *y); | ||
}, | ||
&None => {}, | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.