Skip to content

Commit 8a8b085

Browse files
committed
Fix clippy::uninit_vec warning
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values --> futures-util/src/io/buf_reader.rs:52:13 | 52 | let mut buffer = Vec::with_capacity(capacity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 53 | buffer.set_len(capacity); | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[deny(clippy::uninit_vec)]` on by default = help: initialize the buffer or wrap the content in `MaybeUninit` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
1 parent f3fb74d commit 8a8b085

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

futures-util/src/io/buf_reader.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ impl<R: AsyncRead> BufReader<R> {
4848

4949
/// Creates a new `BufReader` with the specified buffer capacity.
5050
pub fn with_capacity(capacity: usize, inner: R) -> Self {
51-
unsafe {
52-
let mut buffer = Vec::with_capacity(capacity);
53-
buffer.set_len(capacity);
54-
super::initialize(&inner, &mut buffer);
55-
Self { inner, buffer: buffer.into_boxed_slice(), pos: 0, cap: 0 }
56-
}
51+
// TODO: consider using Box<[u8]>::new_uninit_slice once it stabilized
52+
let buffer = vec![0; capacity];
53+
Self { inner, buffer: buffer.into_boxed_slice(), pos: 0, cap: 0 }
5754
}
5855
}
5956

0 commit comments

Comments
 (0)