diff options
| author | bors <bors@rust-lang.org> | 2018-06-26 09:20:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-26 09:20:33 +0000 |
| commit | 309fd8a6fb059d38ea56274968feff2ef738184b (patch) | |
| tree | 01e87f88461c1d465b5827b4864a9bbd71a63bf6 /src/doc | |
| parent | 773ce53ce7b3acb97cfbd3d189dc3fbf33ec05c6 (diff) | |
| parent | 91680347a7ef48ddffd9ff06eedb54a550891cf1 (diff) | |
| download | rust-309fd8a6fb059d38ea56274968feff2ef738184b.tar.gz rust-309fd8a6fb059d38ea56274968feff2ef738184b.zip | |
Auto merge of #49469 - Nokel81:allow-irrefutable-let-patterns, r=nikomatsakis
Implementation of RFC 2086 - Allow Irrefutable Let patterns This is the set of changes for RFC2086. Tracking issue #44495. Rendered [here](https://github.com/rust-lang/rfcs/pull/2086)
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/unstable-book/src/language-features/irrefutable-let-patterns.md | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/irrefutable-let-patterns.md b/src/doc/unstable-book/src/language-features/irrefutable-let-patterns.md new file mode 100644 index 00000000000..46b843778e8 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/irrefutable-let-patterns.md @@ -0,0 +1,28 @@ +# `irrefutable_let_patterns` + +The tracking issue for this feature is: [#44495] + +[#44495]: https://github.com/rust-lang/rust/issues/44495 + +------------------------ + +This feature changes the way that "irrefutable patterns" are handled +in the `if let` and `while let` forms. An *irrefutable pattern* is one +that cannot fail to match -- for example, the `_` pattern matches any +value, and hence it is "irrefutable". Without this feature, using an +irrefutable pattern in an `if let` gives a hard error (since often +this indicates programmer error). But when the feature is enabled, the +error becomes a lint (since in some cases irrefutable patterns are +expected). This means you can use `#[allow]` to silence the lint: + +```rust +#![feature(irrefutable_let_patterns)] + +#[allow(irrefutable_let_patterns)] +fn main() { + // These two examples used to be errors, but now they + // trigger a lint (that is allowed): + if let _ = 5 {} + while let _ = 5 { break; } +} +``` |
