diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-04-09 05:58:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-09 05:58:41 +0200 |
| commit | 9010879c0ac4256e867280421eb94ffae2cd9ad3 (patch) | |
| tree | bc6a8e4a87d4d801c1316772736ad3b312cc0826 | |
| parent | ee8cea8ac48df14c9089720823910a5a8fddbb2c (diff) | |
| parent | e132077db74dd6bd26566dbe3610848e3a771256 (diff) | |
| download | rust-9010879c0ac4256e867280421eb94ffae2cd9ad3.tar.gz rust-9010879c0ac4256e867280421eb94ffae2cd9ad3.zip | |
Rollup merge of #95374 - RalfJung:assert_uninit_valid, r=Mark-Simulacrum
assert_uninit_valid: ensure we detect at least arrays of uninhabited types We can't easily extend this check to *all* arrays (Cc https://github.com/rust-lang/rust/pull/87041), but it turns out the existing check already catches arrays of uninhabited types. So let's make sure it stays that way by adding them to the test.
| -rw-r--r-- | src/test/ui/intrinsics/panic-uninitialized-zeroed.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs index a1cfee944c8..98fd13553c0 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs @@ -104,6 +104,32 @@ fn main() { "attempted to instantiate uninhabited type `Bar`" ); + test_panic_msg( + || mem::uninitialized::<[Foo; 2]>(), + "attempted to instantiate uninhabited type `[Foo; 2]`" + ); + test_panic_msg( + || mem::zeroed::<[Foo; 2]>(), + "attempted to instantiate uninhabited type `[Foo; 2]`" + ); + test_panic_msg( + || MaybeUninit::<[Foo; 2]>::uninit().assume_init(), + "attempted to instantiate uninhabited type `[Foo; 2]`" + ); + + test_panic_msg( + || mem::uninitialized::<[Bar; 2]>(), + "attempted to instantiate uninhabited type `[Bar; 2]`" + ); + test_panic_msg( + || mem::zeroed::<[Bar; 2]>(), + "attempted to instantiate uninhabited type `[Bar; 2]`" + ); + test_panic_msg( + || MaybeUninit::<[Bar; 2]>::uninit().assume_init(), + "attempted to instantiate uninhabited type `[Bar; 2]`" + ); + // Types that do not like zero-initialziation test_panic_msg( || mem::uninitialized::<fn()>(), @@ -199,7 +225,9 @@ fn main() { let _val = mem::zeroed::<OneVariant>(); let _val = mem::zeroed::<Option<&'static i32>>(); let _val = mem::zeroed::<MaybeUninit<NonNull<u32>>>(); + let _val = mem::zeroed::<[!; 0]>(); let _val = mem::uninitialized::<MaybeUninit<bool>>(); + let _val = mem::uninitialized::<[!; 0]>(); // These are UB because they have not been officially blessed, but we await the resolution // of <https://github.com/rust-lang/unsafe-code-guidelines/issues/71> before doing |
