From f52066726dd24ae07b1991b53f48ffa25c2b716d Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Tue, 26 Jan 2021 23:21:00 +0800 Subject: [PATCH] Fix assertion in `MaybeUninit::array_assume_init()` for zero-length arrays --- library/core/src/mem/maybe_uninit.rs | 2 +- library/core/tests/mem.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index fda0553f94c5f..05bcd90d3ca76 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -839,7 +839,7 @@ impl MaybeUninit { // * MaybeUnint does not drop, so there are no double-frees // And thus the conversion is safe unsafe { - intrinsics::assert_inhabited::(); + intrinsics::assert_inhabited::<[T; N]>(); (&array as *const _ as *const [T; N]).read() } } diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 2279a16429f98..38084f401bce6 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -152,6 +152,8 @@ fn uninit_array_assume_init() { let array = unsafe { MaybeUninit::array_assume_init(array) }; assert_eq!(array, [3, 1, 4, 1, 5]); + + let [] = unsafe { MaybeUninit::::array_assume_init([]) }; } #[test]