Skip to content

Commit df33d4d

Browse files
authored
refactor(h1): use UninitSlice::as_uninit_slice_mut() instead of cast (#3618)
1 parent fabb886 commit df33d4d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include = [
2020
]
2121

2222
[dependencies]
23-
bytes = "1"
23+
bytes = "1.2"
2424
http = "1"
2525
http-body = "1"
2626
tokio = { version = "1", features = ["sync"] }

src/proto/h1/io.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt;
33
#[cfg(feature = "server")]
44
use std::future::Future;
55
use std::io::{self, IoSlice};
6-
use std::mem::MaybeUninit;
76
use std::pin::Pin;
87
use std::task::{Context, Poll};
98

@@ -246,8 +245,9 @@ where
246245
self.read_buf.reserve(next);
247246
}
248247

249-
let dst = self.read_buf.chunk_mut();
250-
let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) };
248+
// SAFETY: ReadBuf and poll_read promise not to set any uninitialized
249+
// bytes onto `dst`.
250+
let dst = unsafe { self.read_buf.chunk_mut().as_uninit_slice_mut() };
251251
let mut buf = ReadBuf::uninit(dst);
252252
match Pin::new(&mut self.io).poll_read(cx, buf.unfilled()) {
253253
Poll::Ready(Ok(_)) => {

0 commit comments

Comments
 (0)