]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #60945 - blkerby:fill_buf_nll_doc_example, r=shepmaster
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 19 May 2019 00:31:44 +0000 (02:31 +0200)
committerGitHub <noreply@github.com>
Sun, 19 May 2019 00:31:44 +0000 (02:31 +0200)
Simplify BufRead::fill_buf doc example using NLL

With non-lexical lifetimes, in this example it is no longer necessary to use a block to end the borrow early.

src/libstd/io/mod.rs

index 8fea6251e652a143a2ae29aab6f616692f543080..917199f8ea8d03fe770c6a806a59d54ae207eac4 100644 (file)
@@ -1579,18 +1579,13 @@ pub trait BufRead: Read {
     /// let stdin = io::stdin();
     /// let mut stdin = stdin.lock();
     ///
-    /// // we can't have two `&mut` references to `stdin`, so use a block
-    /// // to end the borrow early.
-    /// let length = {
-    ///     let buffer = stdin.fill_buf().unwrap();
+    /// let buffer = stdin.fill_buf().unwrap();
     ///
-    ///     // work with buffer
-    ///     println!("{:?}", buffer);
-    ///
-    ///     buffer.len()
-    /// };
+    /// // work with buffer
+    /// println!("{:?}", buffer);
     ///
     /// // ensure the bytes we worked with aren't returned again later
+    /// let length = buffer.len();
     /// stdin.consume(length);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]