Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow MaybeUninit docs #254

Merged
merged 1 commit into from
Jun 9, 2022
Merged
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
9 changes: 6 additions & 3 deletions src/impls/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,18 @@ mod const_generics_impl {
#[allow(clippy::uninit_assumed_init)]
// This is safe because we initialize the array immediately after,
// and never return it in case of error
let mut slice: [T; N] = unsafe { MaybeUninit::uninit().assume_init() };
let mut slice: [MaybeUninit<T>; N] = unsafe { MaybeUninit::uninit().assume_init() };
let mut rest = input;
for item in slice.iter_mut() {
let (new_rest, value) = T::read(rest, ctx)?;
*item = value;
item.write(value);
rest = new_rest;
}

Ok((rest, slice))
Ok((rest, unsafe {
// TODO: array_assume_init: https://github.com/rust-lang/rust/issues/80908
(&slice as *const _ as *const [T; N]).read()
}))
}
}

Expand Down