From 900c13e7f465e53a3bae7ff91a1090d6faf29416 Mon Sep 17 00:00:00 2001 From: Marco Conte Date: Fri, 18 Oct 2019 12:28:04 +0100 Subject: [PATCH 1/2] enhance the documentation of std::io::BufReader regarding potential data loss --- src/libstd/io/buffered.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 9593a1bae0a3c..7870c56b476b6 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -24,7 +24,8 @@ use crate::memchr; /// /// When the `BufReader` is dropped, the contents of its buffer will be /// discarded. Creating multiple instances of a `BufReader` on the same -/// stream can cause data loss. +/// stream can cause data loss, as well as reading from the underlying reader +/// after unwrapping the `BufReader` instance with `BufReader::into_inner()`. /// /// [`Read`]: ../../std/io/trait.Read.html /// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read @@ -179,7 +180,8 @@ impl BufReader { /// Unwraps this `BufReader`, returning the underlying reader. /// - /// Note that any leftover data in the internal buffer is lost. + /// Note that any leftover data in the internal buffer is lost. Therefore, + /// a following read from the underlying reader may lead to data loss. /// /// # Examples /// From 5b5196ad65db877c2f140dfc7a25f3fc6f2e40c6 Mon Sep 17 00:00:00 2001 From: Marco Conte Date: Wed, 23 Oct 2019 18:11:41 +0100 Subject: [PATCH 2/2] rephrase sentence regarding data loss when using BufReader::into_inner --- src/libstd/io/buffered.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 7870c56b476b6..ad567c97c2c40 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -24,8 +24,9 @@ use crate::memchr; /// /// When the `BufReader` is dropped, the contents of its buffer will be /// discarded. Creating multiple instances of a `BufReader` on the same -/// stream can cause data loss, as well as reading from the underlying reader -/// after unwrapping the `BufReader` instance with `BufReader::into_inner()`. +/// stream can cause data loss. Reading from the underlying reader after +/// unwrapping the `BufReader` with `BufReader::into_inner` can also cause +/// data loss. /// /// [`Read`]: ../../std/io/trait.Read.html /// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read