Skip to content

Rollup of 8 pull requests #138803

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

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
60805dc
Deduplicate platform stdio types
thaliaarchi Feb 9, 2025
4b59964
Implement optional methods for unsupported stdio
thaliaarchi Feb 7, 2025
15d8363
Implement exact reads for StdinRaw
thaliaarchi Feb 9, 2025
46e3e46
Use unit structs for stateless stdio
thaliaarchi Feb 18, 2025
c58c06a
Return blocks from DropTree::build_mir
bjorn3 Mar 11, 2025
8dc0c0e
Simplify lit_to_mir_constant a bit
bjorn3 Mar 12, 2025
bdaf23b
Forward `stream_position` in `Arc<File>` as well
tbu- Mar 14, 2025
eca391f
Cleanup `LangString::parse`
yotamofek Mar 15, 2025
69a3ad0
Add `MutMirVisitor`
makai410 Mar 18, 2025
ad315f6
Add test for `MutMirVisitor`
makai410 Mar 18, 2025
68267d0
Fix build failure on Trusty
taiki-e Mar 18, 2025
485c14f
Make `crate_hash` not iterate over `hir_crate` owners anymore
oli-obk Mar 19, 2025
a0918b7
jsondocck: Replace `jsonpath_lib` with `jsonpath-rust`
aDotInTheVoid Mar 20, 2025
7ab71c4
tests/rustdoc-json: replace `$.index[*][?` with `$.index[?`
aDotInTheVoid Mar 20, 2025
42631d8
tests/rustdoc-json: replace `$.paths[*][?` with `$.paths[?`
aDotInTheVoid Mar 20, 2025
13335e3
tests/rustdoc-json: change assertions to use RFC 9535 jsonpath
aDotInTheVoid Mar 21, 2025
ff4281d
Rollup merge of #136769 - thaliaarchi:io-optional-methods/stdio, r=jo…
matthiaskrgr Mar 21, 2025
643344e
Rollup merge of #138410 - bjorn3:misc_cleanups, r=compiler-errors
matthiaskrgr Mar 21, 2025
8df7b2a
Rollup merge of #138490 - tbu-:pr_arc_file_pos, r=Noratrieb
matthiaskrgr Mar 21, 2025
8423a89
Rollup merge of #138535 - yotamofek:pr/rustdoc/lang-string-parse-clea…
matthiaskrgr Mar 21, 2025
57b806e
Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinval
matthiaskrgr Mar 21, 2025
e9302b3
Rollup merge of #138673 - taiki-e:trusty-fix, r=Noratrieb
matthiaskrgr Mar 21, 2025
fc20d02
Rollup merge of #138750 - oli-obk:decouple-hir-queries, r=fee1-dead
matthiaskrgr Mar 21, 2025
66d2e2a
Rollup merge of #138763 - aDotInTheVoid:two-years-later, r=GuillaumeG…
matthiaskrgr Mar 21, 2025
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
Implement exact reads for StdinRaw
  • Loading branch information
thaliaarchi committed Mar 11, 2025
commit 15d8363a0c8f7eb6017d09c67e4b0dcec1498449
63 changes: 35 additions & 28 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,53 @@ const fn stderr_raw() -> StderrRaw {

impl Read for StdinRaw {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
handle_ebadf(self.0.read(buf), 0)
handle_ebadf(self.0.read(buf), || Ok(0))
}

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
handle_ebadf(self.0.read_buf(buf), ())
handle_ebadf(self.0.read_buf(buf), || Ok(()))
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
handle_ebadf(self.0.read_vectored(bufs), 0)
handle_ebadf(self.0.read_vectored(bufs), || Ok(0))
}

#[inline]
fn is_read_vectored(&self) -> bool {
self.0.is_read_vectored()
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
if buf.is_empty() {
return Ok(());
}
handle_ebadf(self.0.read_exact(buf), || Err(io::Error::READ_EXACT_EOF))
}

fn read_buf_exact(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
if buf.capacity() == 0 {
return Ok(());
}
handle_ebadf(self.0.read_buf_exact(buf), || Err(io::Error::READ_EXACT_EOF))
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
handle_ebadf(self.0.read_to_end(buf), 0)
handle_ebadf(self.0.read_to_end(buf), || Ok(0))
}

fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
handle_ebadf(self.0.read_to_string(buf), 0)
handle_ebadf(self.0.read_to_string(buf), || Ok(0))
}
}

impl Write for StdoutRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
handle_ebadf(self.0.write(buf), buf.len())
handle_ebadf(self.0.write(buf), || Ok(buf.len()))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let total = || bufs.iter().map(|b| b.len()).sum();
handle_ebadf_lazy(self.0.write_vectored(bufs), total)
let total = || Ok(bufs.iter().map(|b| b.len()).sum());
handle_ebadf(self.0.write_vectored(bufs), total)
}

#[inline]
Expand All @@ -138,30 +152,30 @@ impl Write for StdoutRaw {
}

fn flush(&mut self) -> io::Result<()> {
handle_ebadf(self.0.flush(), ())
handle_ebadf(self.0.flush(), || Ok(()))
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
handle_ebadf(self.0.write_all(buf), ())
handle_ebadf(self.0.write_all(buf), || Ok(()))
}

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
handle_ebadf(self.0.write_all_vectored(bufs), ())
handle_ebadf(self.0.write_all_vectored(bufs), || Ok(()))
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
handle_ebadf(self.0.write_fmt(fmt), ())
handle_ebadf(self.0.write_fmt(fmt), || Ok(()))
}
}

impl Write for StderrRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
handle_ebadf(self.0.write(buf), buf.len())
handle_ebadf(self.0.write(buf), || Ok(buf.len()))
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let total = || bufs.iter().map(|b| b.len()).sum();
handle_ebadf_lazy(self.0.write_vectored(bufs), total)
let total = || Ok(bufs.iter().map(|b| b.len()).sum());
handle_ebadf(self.0.write_vectored(bufs), total)
}

#[inline]
Expand All @@ -170,32 +184,25 @@ impl Write for StderrRaw {
}

fn flush(&mut self) -> io::Result<()> {
handle_ebadf(self.0.flush(), ())
handle_ebadf(self.0.flush(), || Ok(()))
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
handle_ebadf(self.0.write_all(buf), ())
handle_ebadf(self.0.write_all(buf), || Ok(()))
}

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
handle_ebadf(self.0.write_all_vectored(bufs), ())
handle_ebadf(self.0.write_all_vectored(bufs), || Ok(()))
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
handle_ebadf(self.0.write_fmt(fmt), ())
}
}

fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
match r {
Err(ref e) if stdio::is_ebadf(e) => Ok(default),
r => r,
handle_ebadf(self.0.write_fmt(fmt), || Ok(()))
}
}

fn handle_ebadf_lazy<T>(r: io::Result<T>, default: impl FnOnce() -> T) -> io::Result<T> {
fn handle_ebadf<T>(r: io::Result<T>, default: impl FnOnce() -> io::Result<T>) -> io::Result<T> {
match r {
Err(ref e) if stdio::is_ebadf(e) => Ok(default()),
Err(ref e) if stdio::is_ebadf(e) => default(),
r => r,
}
}
Expand Down