Skip to content

Commit c9a7db6

Browse files
committed
Auto merge of rust-lang#120538 - kornelski:read-not-exact, r=m-ou-se
Make File::read_to_end less special Follow-up to rust-lang#117925
2 parents dfa88b3 + fee4992 commit c9a7db6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: library/std/src/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,14 @@ impl Read for &File {
776776
// Reserves space in the buffer based on the file size when available.
777777
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
778778
let size = buffer_capacity_required(self);
779-
buf.try_reserve_exact(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?;
779+
buf.try_reserve(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?;
780780
io::default_read_to_end(self, buf, size)
781781
}
782782

783783
// Reserves space in the buffer based on the file size when available.
784784
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
785785
let size = buffer_capacity_required(self);
786-
buf.try_reserve_exact(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?;
786+
buf.try_reserve(size.unwrap_or(0)).map_err(|_| io::ErrorKind::OutOfMemory)?;
787787
io::default_read_to_string(self, buf, size)
788788
}
789789
}

0 commit comments

Comments
 (0)