`LineWriter` can return an error after a partial write if flushing the inner `BufWriter` fails (https://github.com/rust-lang/rust/blob/cb343c33acf0f9833d8d6eb637234acf4321976b/src/libstd/io/buffered.rs#L766). It should instead return `Ok(bytes_written)`, ignoring the error. ## OLD REPORT: I originally thought this problem was systematic so I audited stdlib. Apparently it isn't... See below. The write trait guarantees: > If an error is returned then no bytes in the buffer were written to this writer. However, this is violated all over stdlib. For example, if `"abc\nde"` is written to a `LineWriter`, the `LineWriter` could write `"abc"`, try to flush, and then return an error due to a failed flush. However, `"abc"` has been written violating the spec. IMO, the solution is to return `Ok(amount_written)` for partial writes and drop the error (if any). This should be safe because of write's write-xor-error guarantee. If the error was transient, the caller never needs to know. Otherwise, they will will learn of it on the next write. Here's everything in the stdlib that implements write (and should be audited): - [x] `Sink` in `librustdoc/test.rs` - [x] `Sink` in `libstd/io/util.rs` - [x] `&'a mut W` in `libstd/io/impls.rs` - [x] `Box<W>` in `libstd/io/impls.rs` - [x] `&'a mut [u8]` in `libstd/io/impls.rs` - [x] `Vec<u8>` in `libstd/io/impls.rs` - [x] `Cursor<&'a mut [u8]>` in `libstd/io/cursor.rs` - [x] `Cursor<Vec<u8>>` in `libstd/io/cursor.rs` - [x] `Cursor<Box<[u8]>>` in `libstd/io/cursor.rs` - [x] `StdoutRaw` in `libstd/io/stdio.rs` - [x] `StderrRaw` in `libstd/io/stdio.rs` - [x] `Maybe<W>` in `libstd/io/stdio.rs` - [x] `Stdout` in `libstd/io/stdio.rs` - [x] `StdoutLock<'a>` in `libstd/io/stdio.rs` - [x] `Stderr` in `libstd/io/stdio.rs` - [x] `StderrLock<'a>` in `libstd/io/stdio.rs` - [x] `BufWriter<W>` in `libstd/io/buffered.rs` - [ ] `LineWriter<W>` in `libstd/io/buffered.rs` (buggy) - [x] `Broadcast<T, U>` in `libstd/io/mod.rs` (buggy but unfixable and deprecated). - [x] `TcpStream` in `libstd/net/tcp.rs` - [x] `&'a TcpStream` in `libstd/net/tcp.rs` - [x] `Stderr` in `libstd/sys/unix/stdio.rs` - [ ] `Stderr` in `libstd/sys/windows/stdio.rs` (panics on partial write) - [x] `ChildStdin` in `libstd/process.rs` - [x] `File` in `libstd/fs.rs` - [x] `&'a File` in `libstd/fs.rs`