diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 6b1dd1b5af4c9..fee529993715b 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -261,7 +261,7 @@ pub fn read>(path: P) -> io::Result> { let mut file = File::open(path)?; let size = file.metadata().map(|m| m.len() as usize).ok(); let mut bytes = Vec::new(); - bytes.try_reserve_exact(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?; + bytes.try_reserve_exact(size.unwrap_or(0))?; io::default_read_to_end(&mut file, &mut bytes, size)?; Ok(bytes) } @@ -304,7 +304,7 @@ pub fn read_to_string>(path: P) -> io::Result { let mut file = File::open(path)?; let size = file.metadata().map(|m| m.len() as usize).ok(); let mut string = String::new(); - string.try_reserve_exact(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?; + string.try_reserve_exact(size.unwrap_or(0))?; io::default_read_to_string(&mut file, &mut string, size)?; Ok(string) } @@ -777,14 +777,14 @@ impl Read for &File { // Reserves space in the buffer based on the file size when available. fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { let size = buffer_capacity_required(self); - buf.try_reserve(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?; + buf.try_reserve(size.unwrap_or(0))?; io::default_read_to_end(self, buf, size) } // Reserves space in the buffer based on the file size when available. fn read_to_string(&mut self, buf: &mut String) -> io::Result { let size = buffer_capacity_required(self); - buf.try_reserve(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?; + buf.try_reserve(size.unwrap_or(0))?; io::default_read_to_string(self, buf, size) } } diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index e0dc9f96ae9b2..83db332ee2558 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -344,7 +344,7 @@ impl Read for BufReader { // delegate to the inner implementation. fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { let inner_buf = self.buffer(); - buf.try_reserve(inner_buf.len()).map_err(|_| io::ErrorKind::OutOfMemory)?; + buf.try_reserve(inner_buf.len())?; buf.extend_from_slice(inner_buf); let nread = inner_buf.len(); self.discard_buffer(); diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 557e64dc8674e..cb972abd2b821 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -304,7 +304,7 @@ impl Read for &[u8] { #[inline] fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { let len = self.len(); - buf.try_reserve(len).map_err(|_| ErrorKind::OutOfMemory)?; + buf.try_reserve(len)?; buf.extend_from_slice(*self); *self = &self[len..]; Ok(len) @@ -452,7 +452,7 @@ impl Read for VecDeque { fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { // The total len is known upfront so we can reserve it in a single call. let len = self.len(); - buf.try_reserve(len).map_err(|_| ErrorKind::OutOfMemory)?; + buf.try_reserve(len)?; let (front, back) = self.as_slices(); buf.extend_from_slice(front); diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 102db62fced34..0d1c2702b7829 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -465,7 +465,7 @@ pub(crate) fn default_read_to_end( if buf.len() == buf.capacity() { // buf is full, need more space - buf.try_reserve(PROBE_SIZE).map_err(|_| ErrorKind::OutOfMemory)?; + buf.try_reserve(PROBE_SIZE)?; } let mut spare = buf.spare_capacity_mut(); @@ -834,7 +834,7 @@ pub trait Read { /// if src_buf.is_empty() { /// break; /// } - /// dest_vec.try_reserve(src_buf.len()).map_err(|_| io::ErrorKind::OutOfMemory)?; + /// dest_vec.try_reserve(src_buf.len())?; /// dest_vec.extend_from_slice(src_buf); /// /// // Any irreversible side effects should happen after `try_reserve` succeeds,