diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 9f9ee4af5c8..46f04c7cd39 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -474,15 +474,8 @@ impl Read for VecDeque { #[inline] fn read_to_string(&mut self, buf: &mut String) -> io::Result { - // We have to use a single contiguous slice because the `VecDequeue` might be split in the - // middle of an UTF-8 character. - let len = self.len(); - let content = self.make_contiguous(); - let string = str::from_utf8(content).map_err(|_| io::Error::INVALID_UTF8)?; - buf.try_reserve(len)?; - buf.push_str(string); - self.clear(); - Ok(len) + // SAFETY: We only append to the buffer + unsafe { io::append_to_string(buf, |buf| self.read_to_end(buf)) } } }