diff options
| author | hyd-dev <yd-huang@outlook.com> | 2021-01-26 23:21:00 +0800 |
|---|---|---|
| committer | hyd-dev <yd-huang@outlook.com> | 2021-01-27 00:16:58 +0800 |
| commit | f52066726dd24ae07b1991b53f48ffa25c2b716d (patch) | |
| tree | 4f877a70e4bff9f0cbae723f050eece8faae92e0 /library | |
| parent | 1483e67addd37d9bd20ba3b4613b678ee9ad4d68 (diff) | |
| download | rust-f52066726dd24ae07b1991b53f48ffa25c2b716d.tar.gz rust-f52066726dd24ae07b1991b53f48ffa25c2b716d.zip | |
Fix assertion in `MaybeUninit::array_assume_init()` for zero-length arrays
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/mem/maybe_uninit.rs | 2 | ||||
| -rw-r--r-- | library/core/tests/mem.rs | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index fda0553f94c..05bcd90d3ca 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -839,7 +839,7 @@ impl<T> MaybeUninit<T> { // * MaybeUnint does not drop, so there are no double-frees // And thus the conversion is safe unsafe { - intrinsics::assert_inhabited::<T>(); + 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 2279a16429f..38084f401bc 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] |
