diff options
| author | bors <bors@rust-lang.org> | 2021-07-23 20:26:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-23 20:26:33 +0000 |
| commit | 67b03007cf40f2331892d5b0f65d2917ac3603d5 (patch) | |
| tree | fc0eeae25f29e324e89f3ad0d11045fcce5f446f /library/std | |
| parent | 4a1f419e641c7ec56a60f1714ced5c343e0a2b38 (diff) | |
| parent | a6515816a644be708578328b425a60c7f1e6168e (diff) | |
| download | rust-67b03007cf40f2331892d5b0f65d2917ac3603d5.tar.gz rust-67b03007cf40f2331892d5b0f65d2917ac3603d5.zip | |
Auto merge of #87413 - JohnTitor:rollup-dht22jk, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #86410 (VecMap::get_value_matching should return just one element) - #86790 (Document iteration order of `retain` functions) - #87171 (Remove Option from BufWriter) - #87175 (Stabilize `into_parts()` and `into_error()`) - #87185 (Fix panics on Windows when the build was cancelled) - #87191 (Package LLVM libs for the target rather than the build host) - #87255 (better support for running libcore tests with Miri) - #87266 (Add testcase for 87076) - #87283 (Add `--codegen-backends=foo,bar` configure flag) - #87322 (fix: clarify suggestion that `&T` must refer to `T: Sync` for `&T: Send`) - #87358 (Fix `--dry-run` when download-ci-llvm is set) - #87380 (Don't default to `submodules = true` unless the rust repo has a .git directory) - #87398 (Add test for fonts used for module items) - #87412 (Add missing article) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/collections/hash/map.rs | 1 | ||||
| -rw-r--r-- | library/std/src/collections/hash/set.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/buffered/bufwriter.rs | 24 | ||||
| -rw-r--r-- | library/std/src/io/buffered/mod.rs | 6 |
4 files changed, 18 insertions, 14 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index fac285c96f0..4a5efab9055 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -934,6 +934,7 @@ where /// Retains only the elements specified by the predicate. /// /// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`. + /// The elements are visited in unsorted (and unspecified) order. /// /// # Examples /// diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 272e1c2be2b..1a2a8afac8b 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -912,6 +912,7 @@ where /// Retains only the elements specified by the predicate. /// /// In other words, remove all elements `e` such that `f(&e)` returns `false`. + /// The elements are visited in unsorted (and unspecified) order. /// /// # Examples /// diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index ef2769d431f..c98244132be 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -68,7 +68,7 @@ use crate::ptr; /// [`flush`]: BufWriter::flush #[stable(feature = "rust1", since = "1.0.0")] pub struct BufWriter<W: Write> { - inner: Option<W>, + inner: W, // The buffer. Avoid using this like a normal `Vec` in common code paths. // That is, don't use `buf.push`, `buf.extend_from_slice`, or any other // methods that require bounds checking or the like. This makes an enormous @@ -112,7 +112,7 @@ impl<W: Write> BufWriter<W> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W> { - BufWriter { inner: Some(inner), buf: Vec::with_capacity(capacity), panicked: false } + BufWriter { inner, buf: Vec::with_capacity(capacity), panicked: false } } /// Send data in our local buffer into the inner writer, looping as @@ -161,10 +161,9 @@ impl<W: Write> BufWriter<W> { } let mut guard = BufGuard::new(&mut self.buf); - let inner = self.inner.as_mut().unwrap(); while !guard.done() { self.panicked = true; - let r = inner.write(guard.remaining()); + let r = self.inner.write(guard.remaining()); self.panicked = false; match r { @@ -212,7 +211,7 @@ impl<W: Write> BufWriter<W> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get_ref(&self) -> &W { - self.inner.as_ref().unwrap() + &self.inner } /// Gets a mutable reference to the underlying writer. @@ -232,7 +231,7 @@ impl<W: Write> BufWriter<W> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut W { - self.inner.as_mut().unwrap() + &mut self.inner } /// Returns a reference to the internally buffered data. @@ -308,7 +307,7 @@ impl<W: Write> BufWriter<W> { pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> { match self.flush_buf() { Err(e) => Err(IntoInnerError::new(self, e)), - Ok(()) => Ok(self.inner.take().unwrap()), + Ok(()) => Ok(self.into_raw_parts().0), } } @@ -339,7 +338,12 @@ impl<W: Write> BufWriter<W> { pub fn into_raw_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) { let buf = mem::take(&mut self.buf); let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; - (self.inner.take().unwrap(), buf) + + // SAFETY: forget(self) prevents double dropping inner + let inner = unsafe { ptr::read(&mut self.inner) }; + mem::forget(self); + + (inner, buf) } // Ensure this function does not get inlined into `write`, so that it @@ -643,7 +647,7 @@ where { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BufWriter") - .field("writer", &self.inner.as_ref().unwrap()) + .field("writer", &self.inner) .field("buffer", &format_args!("{}/{}", self.buf.len(), self.buf.capacity())) .finish() } @@ -663,7 +667,7 @@ impl<W: Write + Seek> Seek for BufWriter<W> { #[stable(feature = "rust1", since = "1.0.0")] impl<W: Write> Drop for BufWriter<W> { fn drop(&mut self) { - if self.inner.is_some() && !self.panicked { + if !self.panicked { // dtors should not panic, so we ignore a failed flush let _r = self.flush_buf(); } diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 65497817f81..38076ab3a2b 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -133,7 +133,6 @@ impl<W> IntoInnerError<W> { /// /// # Example /// ``` - /// #![feature(io_into_inner_error_parts)] /// use std::io::{BufWriter, ErrorKind, Write}; /// /// let mut not_enough_space = [0u8; 10]; @@ -143,7 +142,7 @@ impl<W> IntoInnerError<W> { /// let err = into_inner_err.into_error(); /// assert_eq!(err.kind(), ErrorKind::WriteZero); /// ``` - #[unstable(feature = "io_into_inner_error_parts", issue = "79704")] + #[stable(feature = "io_into_inner_error_parts", since = "1.55.0")] pub fn into_error(self) -> Error { self.1 } @@ -156,7 +155,6 @@ impl<W> IntoInnerError<W> { /// /// # Example /// ``` - /// #![feature(io_into_inner_error_parts)] /// use std::io::{BufWriter, ErrorKind, Write}; /// /// let mut not_enough_space = [0u8; 10]; @@ -167,7 +165,7 @@ impl<W> IntoInnerError<W> { /// assert_eq!(err.kind(), ErrorKind::WriteZero); /// assert_eq!(recovered_writer.buffer(), b"t be actually written"); /// ``` - #[unstable(feature = "io_into_inner_error_parts", issue = "79704")] + #[stable(feature = "io_into_inner_error_parts", since = "1.55.0")] pub fn into_parts(self) -> (Error, W) { (self.1, self.0) } |
