From cbba940daf73abf9dc26e1f270bd1095aea7b9a3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 1 Jun 2021 16:30:13 +0100 Subject: [PATCH 1/3] BufWriter: actually export WriterPanicked error I didn't notice the submodule, which means I failed to re-export this to make it actually-public. Reported-by: Andrew Gallant Signed-off-by: Ian Jackson --- library/std/src/io/buffered/mod.rs | 2 ++ library/std/src/io/mod.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 38076ab3a2b7b..896c7b8684f86 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -14,6 +14,8 @@ use crate::io::Error; pub use bufreader::BufReader; pub use bufwriter::BufWriter; +#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +pub use bufwriter::WriterPanicked; pub use linewriter::LineWriter; use linewritershim::LineWriterShim; diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index cc615b95f8625..dec8251ee0158 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -264,6 +264,8 @@ use crate::sys_common::memchr; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::IntoInnerError; +#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +pub use self::buffered::WriterPanicked; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; #[stable(feature = "rust1", since = "1.0.0")] From 66f38075aff7d168795544638893d87217defe64 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 1 Jun 2021 16:47:26 +0100 Subject: [PATCH 2/3] BufWriter: rename `into_parts` from `into_raw_parts` I looked in stdlib and as @BurntSushi thought, `raw` is generally used for raw pointers, or other hazardous kinds of thing. stdlib does not have `into_parts` apart from the one I added to `IntoInnerError`. I did an ad-hoc search of the rustdocs for my current game project Otter, which includes quite a large number of dependencies. `into_parts` seems heavily used for things quite like this. So change this name. Suggested-by: Andrew Gallant Signed-off-by: Ian Jackson --- library/std/src/io/buffered/bufwriter.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index c98244132befd..88eec8dff9ecc 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -307,7 +307,7 @@ impl BufWriter { pub fn into_inner(mut self) -> Result>> { match self.flush_buf() { Err(e) => Err(IntoInnerError::new(self, e)), - Ok(()) => Ok(self.into_raw_parts().0), + Ok(()) => Ok(self.into_parts().0), } } @@ -318,7 +318,7 @@ impl BufWriter { /// In this case, we return `WriterPanicked` for the buffered data (from which the buffer /// contents can still be recovered). /// - /// `into_raw_parts` makes no attempt to flush data and cannot fail. + /// `into_parts` makes no attempt to flush data and cannot fail. /// /// # Examples /// @@ -330,12 +330,12 @@ impl BufWriter { /// let mut stream = BufWriter::new(buffer.as_mut()); /// write!(stream, "too much data").unwrap(); /// stream.flush().expect_err("it doesn't fit"); - /// let (recovered_writer, buffered_data) = stream.into_raw_parts(); + /// let (recovered_writer, buffered_data) = stream.into_parts(); /// assert_eq!(recovered_writer.len(), 0); /// assert_eq!(&buffered_data.unwrap(), b"ata"); /// ``` #[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] - pub fn into_raw_parts(mut self) -> (W, Result, WriterPanicked>) { + pub fn into_parts(mut self) -> (W, Result, WriterPanicked>) { let buf = mem::take(&mut self.buf); let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; @@ -445,7 +445,7 @@ impl BufWriter { } #[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] -/// Error returned for the buffered data from `BufWriter::into_raw_parts`, when the underlying +/// Error returned for the buffered data from `BufWriter::into_parts`, when the underlying /// writer has previously panicked. Contains the (possibly partly written) buffered data. /// /// # Example @@ -467,7 +467,7 @@ impl BufWriter { /// stream.flush().unwrap() /// })); /// assert!(result.is_err()); -/// let (recovered_writer, buffered_data) = stream.into_raw_parts(); +/// let (recovered_writer, buffered_data) = stream.into_parts(); /// assert!(matches!(recovered_writer, PanickingWriter)); /// assert_eq!(buffered_data.unwrap_err().into_inner(), b"some data"); /// ``` From bf30c51541c533830ec46ae65d9863666055a74b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 19 Jul 2021 17:33:55 +0100 Subject: [PATCH 3/3] Rename feature gate bufwriter_into_parts from bufwriter_into_raw_parts As requested https://github.com/rust-lang/rust/pull/85901#pullrequestreview-698404772 Signed-off-by: Ian Jackson --- library/std/src/io/buffered/bufwriter.rs | 16 ++++++++-------- library/std/src/io/buffered/mod.rs | 2 +- library/std/src/io/mod.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 88eec8dff9ecc..9da5fbff9cf02 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -323,7 +323,7 @@ impl BufWriter { /// # Examples /// /// ``` - /// #![feature(bufwriter_into_raw_parts)] + /// #![feature(bufwriter_into_parts)] /// use std::io::{BufWriter, Write}; /// /// let mut buffer = [0u8; 10]; @@ -334,7 +334,7 @@ impl BufWriter { /// assert_eq!(recovered_writer.len(), 0); /// assert_eq!(&buffered_data.unwrap(), b"ata"); /// ``` - #[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] + #[unstable(feature = "bufwriter_into_parts", issue = "80690")] pub fn into_parts(mut self) -> (W, Result, WriterPanicked>) { let buf = mem::take(&mut self.buf); let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; @@ -444,14 +444,14 @@ impl BufWriter { } } -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] /// Error returned for the buffered data from `BufWriter::into_parts`, when the underlying /// writer has previously panicked. Contains the (possibly partly written) buffered data. /// /// # Example /// /// ``` -/// #![feature(bufwriter_into_raw_parts)] +/// #![feature(bufwriter_into_parts)] /// use std::io::{self, BufWriter, Write}; /// use std::panic::{catch_unwind, AssertUnwindSafe}; /// @@ -478,7 +478,7 @@ pub struct WriterPanicked { impl WriterPanicked { /// Returns the perhaps-unwritten data. Some of this data may have been written by the /// panicking call(s) to the underlying writer, so simply writing it again is not a good idea. - #[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] + #[unstable(feature = "bufwriter_into_parts", issue = "80690")] pub fn into_inner(self) -> Vec { self.buf } @@ -487,7 +487,7 @@ impl WriterPanicked { "BufWriter inner writer panicked, what data remains unwritten is not known"; } -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] impl error::Error for WriterPanicked { #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { @@ -495,14 +495,14 @@ impl error::Error for WriterPanicked { } } -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] impl fmt::Display for WriterPanicked { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", Self::DESCRIPTION) } } -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] impl fmt::Debug for WriterPanicked { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("WriterPanicked") diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 896c7b8684f86..8cfffc2fd35a4 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -14,7 +14,7 @@ use crate::io::Error; pub use bufreader::BufReader; pub use bufwriter::BufWriter; -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] pub use bufwriter::WriterPanicked; pub use linewriter::LineWriter; use linewritershim::LineWriterShim; diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index dec8251ee0158..c58abf2a737a3 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -264,7 +264,7 @@ use crate::sys_common::memchr; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::IntoInnerError; -#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")] +#[unstable(feature = "bufwriter_into_parts", issue = "80690")] pub use self::buffered::WriterPanicked; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::{BufReader, BufWriter, LineWriter};