Skip to content

Commit 1b8b2dc

Browse files
committed
Avoid MaybeUninit::uninit_array()
1 parent 2f9bd1a commit 1b8b2dc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/std/src/sys/windows/stdio.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn write(
170170
}
171171

172172
fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result<usize> {
173-
let mut utf16: [MaybeUninit<u16>; MAX_BUFFER_SIZE / 2] = MaybeUninit::uninit_array();
173+
let mut utf16 = [MaybeUninit::<u16>::uninit(); MAX_BUFFER_SIZE / 2];
174174
let mut len_utf16 = 0;
175175
for (chr, dest) in utf8.encode_utf16().zip(utf16.iter_mut()) {
176176
*dest = MaybeUninit::new(chr);
@@ -252,7 +252,7 @@ impl io::Read for Stdin {
252252
return Ok(bytes_copied);
253253
} else if buf.len() - bytes_copied < 4 {
254254
// Not enough space to get a UTF-8 byte. We will use the incomplete UTF8.
255-
let mut utf16_buf = [MaybeUninit::new(1); 1];
255+
let mut utf16_buf = [MaybeUninit::new(0); 1];
256256
// Read one u16 character.
257257
let read = read_u16s_fixup_surrogates(handle, &mut utf16_buf, 1, &mut self.surrogate)?;
258258
// Read bytes, using the (now-empty) self.incomplete_utf8 as extra space.
@@ -267,8 +267,8 @@ impl io::Read for Stdin {
267267
bytes_copied += self.incomplete_utf8.read(&mut buf[bytes_copied..]);
268268
Ok(bytes_copied)
269269
} else {
270-
let mut utf16_buf: [MaybeUninit<u16>; MAX_BUFFER_SIZE / 2] =
271-
MaybeUninit::uninit_array();
270+
let mut utf16_buf = [MaybeUninit::<u16>::uninit(); MAX_BUFFER_SIZE / 2];
271+
272272
// In the worst case, a UTF-8 string can take 3 bytes for every `u16` of a UTF-16. So
273273
// we can read at most a third of `buf.len()` chars and uphold the guarantee no data gets
274274
// lost.

0 commit comments

Comments
 (0)