Skip to content

write_all assumes that a write returning 0 is a kind of EOF #145959

@RalfJung

Description

@RalfJung

The code is quite self-explaining:

rust/library/std/src/io/mod.rs

Lines 1835 to 1847 in a7e8fe7

fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => {
return Err(Error::WRITE_ALL_EOF);
}
Ok(n) => buf = &buf[n..],
Err(ref e) if e.is_interrupted() => {}
Err(e) => return Err(e),
}
}
Ok(())
}

However, reading the write() docs, I see no justification for this. As far as I can tell, write is allowed to spuriously return 0 as a form of "short write". This random website also says so.

Cc @the8472

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions