Skip to content

Commit f520667

Browse files
author
hyd-dev
committed
Fix assertion in MaybeUninit::array_assume_init() for zero-length arrays
1 parent 1483e67 commit f520667

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

library/core/src/mem/maybe_uninit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl<T> MaybeUninit<T> {
839839
// * MaybeUnint does not drop, so there are no double-frees
840840
// And thus the conversion is safe
841841
unsafe {
842-
intrinsics::assert_inhabited::<T>();
842+
intrinsics::assert_inhabited::<[T; N]>();
843843
(&array as *const _ as *const [T; N]).read()
844844
}
845845
}

library/core/tests/mem.rs

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ fn uninit_array_assume_init() {
152152
let array = unsafe { MaybeUninit::array_assume_init(array) };
153153

154154
assert_eq!(array, [3, 1, 4, 1, 5]);
155+
156+
let [] = unsafe { MaybeUninit::<!>::array_assume_init([]) };
155157
}
156158

157159
#[test]

0 commit comments

Comments
 (0)