Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #122256

Merged
merged 23 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift click to select a range
709ea74
Add Read Impl for &Stdin
Dajamante Jul 11, 2022
8ea2922
Make `impl<Fd: AsFd>` impl take `?Sized`
nbdd0121 Aug 9, 2023
f4aeb70
Make `impl<T: AsHandle>` impl take `?Sized`
nbdd0121 Jan 28, 2024
e49cd1c
TryReserveError to ErrorKind::OutOfMemory
kornelski Feb 21, 2024
aa581f0
Remove unnecessary map_err
kornelski Feb 21, 2024
ea476b1
on the fly type casting for `build.rustc` and `build.cargo`
onur-ozkan Feb 23, 2024
b921a34
Fix stable feature name and stabilization version of Read for &Stdin
dtolnay Feb 26, 2024
b18280f
Fill in Read::read_buf for &Stdin
dtolnay Feb 26, 2024
2283478
Implement junction_point
ChrisDenton Feb 27, 2024
f27a22c
try_with_capacity for RawVec
kornelski Jan 30, 2024
78fb977
try_with_capacity for Vec, VecDeque, String
kornelski Jan 30, 2024
784e6a1
Move capacity_overflow function to make ui tests change less
kornelski Jan 31, 2024
0a00749
Implement MaybeUninit::fill{,_with,_from}
ajwock Feb 18, 2024
52501c2
bump itertools to 0.12
klensy Feb 23, 2024
2de98c8
remove unused derive_more dep
klensy Feb 28, 2024
0a8ea93
Rollup merge of #99153 - Dajamante:issue/95622, r=dtolnay
Nadrieril Mar 9, 2024
5b6d30a
Rollup merge of #114655 - nbdd0121:io-safety, r=dtolnay
Nadrieril Mar 9, 2024
e3c0158
Rollup merge of #120504 - kornelski:try_with_capacity, r=Amanieu
Nadrieril Mar 9, 2024
cbd59d0
Rollup merge of #121280 - ajwock:maybeuninit_fill, r=Amanieu
Nadrieril Mar 9, 2024
9ccf798
Rollup merge of #121403 - kornelski:io-oom, r=dtolnay
Nadrieril Mar 9, 2024
5d4e3d9
Rollup merge of #121526 - onur-ozkan:minor-improvement, r=Mark-Simula…
Nadrieril Mar 9, 2024
bc3bc2b
Rollup merge of #121584 - klensy:itertools-up, r=Mark-Simulacrum
Nadrieril Mar 9, 2024
13ca978
Rollup merge of #121711 - ChrisDenton:junction, r=Mark-Simulacrum
Nadrieril Mar 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unnecessary map_err
  • Loading branch information
kornelski committed Feb 21, 2024
commit aa581f0a0a3fbb61efe1f37786c237b2733dfbfa
8 changes: 4 additions & 4 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 261,7 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
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)
}
Expand Down Expand Up @@ -304,7 304,7 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
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)
}
Expand Down Expand Up @@ -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<u8>) -> io::Result<usize> {
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<usize> {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 344,7 @@ impl<R: ?Sized Read> Read for BufReader<R> {
// delegate to the inner implementation.
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
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();
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 304,7 @@ impl Read for &[u8] {
#[inline]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
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)
Expand Down Expand Up @@ -452,7 452,7 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
// 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);
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 465,7 @@ pub(crate) fn default_read_to_end<R: Read ?Sized>(

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();
Expand Down Expand Up @@ -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,
Expand Down
Loading