Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions futures-util/src/io/fill_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ where
let reader = this.reader.take().expect("Polled FillBuf after completion");

match Pin::new(&mut *reader).poll_fill_buf(cx) {
// The reader can try to fill its buffer again if it returned no data, according to the
// AsyncBufRead contract. Don't poll again in that case, in order to make the
// Poll::Pending match arm below truly unreachable.
Poll::Ready(Ok([])) => Poll::Ready(Ok(&[])),

// With polonius it is possible to remove this inner match and just have the correct
// lifetime of the reference inferred based on which branch is taken
Poll::Ready(Ok(_)) => match Pin::new(reader).poll_fill_buf(cx) {
Expand Down
13 changes: 13 additions & 0 deletions futures/tests/io_buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,16 @@ fn maybe_pending_seek() {
Pin::new(&mut reader).consume(1);
assert_eq!(run(reader.seek(SeekFrom::Current(-2))).ok(), Some(3));
}

#[test]
fn fill_buf_pending_after_eof() {
let inner: &[u8] = &[1, 2];
let mut reader = BufReader::with_capacity(inner.len(), MaybePending::new(inner));

let buf = run(reader.fill_buf()).unwrap();
assert_eq!(buf, inner);
reader.consume_unpin(2);

let buf = run(reader.fill_buf()).unwrap();
assert_eq!(buf, []);
}