diff options
| author | bors <bors@rust-lang.org> | 2019-07-08 01:32:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-08 01:32:50 +0000 |
| commit | db592f4627251cfd8571a05cf8e06a56be9470c2 (patch) | |
| tree | 89d3935978ce188c23f8c7e818a39c5d1655235f /src/libstd | |
| parent | a8247238e3c948bdaf440c8070193a4beea0dd9b (diff) | |
| parent | ada2684c807a257eac75787d98c1c129a2500c92 (diff) | |
| download | rust-db592f4627251cfd8571a05cf8e06a56be9470c2.tar.gz rust-db592f4627251cfd8571a05cf8e06a56be9470c2.zip | |
Auto merge of #62485 - Centril:rollup-gg3it1u, r=Centril
Rollup of 5 pull requests Successful merges: - #62356 (Implement Option::contains and Result::contains) - #62462 (Document `while` keyword) - #62472 (Normalize use of backticks in compiler messages p2) - #62477 (Re-add bootstrap attribute to libunwind for llvm-libunwind feature) - #62478 (normalize use of backticks for compiler messages in librustc_codegen) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/keyword_docs.rs | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index d133c2f5cb1..d18fcb4a1da 100644 --- a/src/libstd/keyword_docs.rs +++ b/src/libstd/keyword_docs.rs @@ -608,6 +608,62 @@ mod in_keyword { } /// [Reference]: ../reference/statements.html#let-statements mod let_keyword { } +#[doc(keyword = "while")] +// +/// Loop while a condition is upheld. +/// +/// A `while` expression is used for predicate loops. The `while` expression runs the conditional +/// expression before running the loop body, then runs the loop body if the conditional +/// expression evaluates to `true`, or exits the loop otherwise. +/// +/// ```rust +/// let mut counter = 0; +/// +/// while counter < 10 { +/// println!("{}", counter); +/// counter += 1; +/// } +/// ``` +/// +/// Like the [`for`] expression, we can use `break` and `continue`. A `while` expression +/// cannot break with a value and always evaluates to `()` unlike [`loop`]. +/// +/// ```rust +/// let mut i = 1; +/// +/// while i < 100 { +/// i *= 2; +/// if i == 64 { +/// break; // Exit when `i` is 64. +/// } +/// } +/// ``` +/// +/// As `if` expressions have their pattern matching variant in `if let`, so too do `while` +/// expressions with `while let`. The `while let` expression matches the pattern against the +/// expression, then runs the loop body if pattern matching succeeds, or exits the loop otherwise. +/// We can use `break` and `continue` in `while let` expressions just like in `while`. +/// +/// ```rust +/// let mut counter = Some(0); +/// +/// while let Some(i) = counter { +/// if i == 10 { +/// counter = None; +/// } else { +/// println!("{}", i); +/// counter = Some (i + 1); +/// } +/// } +/// ``` +/// +/// For more information on `while` and loops in general, see the [reference]. +/// +/// [`for`]: keyword.for.html +/// [`loop`]: keyword.loop.html +/// [reference]: ../reference/expressions/loop-expr.html#predicate-loops +mod while_keyword { } + #[doc(keyword = "loop")] // /// Loop indefinitely. @@ -922,15 +978,6 @@ mod use_keyword { } /// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 mod where_keyword { } -#[doc(keyword = "while")] -// -/// Loop while a condition is upheld. -/// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! -/// -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 -mod while_keyword { } - // 2018 Edition keywords #[unstable(feature = "async_await", issue = "50547")] |
