Skip to content

Commit d6143c9

Browse files
authored
io: improve safety comment on FillBuf (#4476)
1 parent 5690f0c commit d6143c9

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

tokio/src/io/util/fill_buf.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin> Future for FillBuf<'a, R> {
4040
// Safety: This is necessary only due to a limitation in the
4141
// borrow checker. Once Rust starts using the polonius borrow
4242
// checker, this can be simplified.
43+
//
44+
// The safety of this transmute relies on the fact that the
45+
// value of `reader` is `None` when we return in this branch.
46+
// Otherwise the caller could poll us again after
47+
// completion, and access the mutable reference while the
48+
// returned immutable reference still exists.
4349
let slice = std::mem::transmute::<&[u8], &'a [u8]>(slice);
4450
Poll::Ready(Ok(slice))
4551
},

0 commit comments

Comments
 (0)