]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #88507 - atsuzaki:slice-fill-maybeuninit-test, r=RalfJung
authorMara Bos <m-ou.se@m-ou.se>
Fri, 3 Sep 2021 11:30:47 +0000 (13:30 +0200)
committerGitHub <noreply@github.com>
Fri, 3 Sep 2021 11:30:47 +0000 (13:30 +0200)
Add test case for using `slice::fill` with MaybeUninit

Adds test for #87891

Looks alright? `@RalfJung`
Fixes #87891

library/core/tests/slice.rs

index 43e2af3eb18d262403b9788e5db808a113ee1a64..c591dd3e1a6dbbca75aa3af7e1266f25affae5f0 100644 (file)
@@ -1,5 +1,6 @@
 use core::cell::Cell;
 use core::cmp::Ordering;
+use core::mem::MaybeUninit;
 use core::result::Result::{Err, Ok};
 
 #[test]
@@ -2144,3 +2145,10 @@ fn foo(x: &Cell<isize>) -> Foo<'_> {
 
     assert_eq!(x.get(), 1);
 }
+
+#[test]
+fn test_slice_fill_with_uninit() {
+    // This should not UB. See #87891
+    let mut a = [MaybeUninit::<u8>::uninit(); 10];
+    a.fill(MaybeUninit::uninit());
+}