Skip to content

Commit cb599cc

Browse files
Remove mem::uninitalized from tests
This purges uses of uninitialized where possible from test cases. Some are merely moved over to the equally bad pattern of MaybeUninit::uninit().assume_init() but with an annotation that this is "the best we can do".
1 parent 3982d35 commit cb599cc

File tree

15 files changed

+49
-39
lines changed

15 files changed

+49
-39
lines changed

src/test/run-make-fulldeps/sanitizer-memory/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
all:
88
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | $(CGREP) librustc_msan
99
$(TMPDIR)/uninit 2>&1 | $(CGREP) use-of-uninitialized-value
10+
$(RUSTC) -g -Z sanitizer=memory -Z print-link-args maybeuninit.rs | $(CGREP) librustc_msan
11+
$(TMPDIR)/maybeuninit 2>&1 | $(CGREP) use-of-uninitialized-value
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::mem::MaybeUninit;
2+
3+
fn main() {
4+
// This is technically not sound -- but we're literally trying to test
5+
// that the sanitizer catches this, so I guess "intentionally unsound"?
6+
let xs: [u8; 4] = unsafe { MaybeUninit::uninit().assume_init() };
7+
let y = xs[0] + xs[1];
8+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::mem;
2-
31
fn main() {
2+
// This is technically not sound -- but we're literally trying to test
3+
// that the sanitizer catches this, so I guess "intentionally unsound"?
44
#[allow(deprecated)]
5-
let xs: [u8; 4] = unsafe { mem::uninitialized() };
5+
let xs: [u8; 4] = unsafe { std::mem::uninitialized() };
66
let y = xs[0] + xs[1];
77
}

src/test/rustdoc/issue-52873.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl<U: Unsigned, B: Bit> Add<B0> for UInt<U, B> {
105105
impl<U: Unsigned> Add<U> for UTerm {
106106
type Output = U;
107107
fn add(self, _: U) -> Self::Output {
108-
#[allow(deprecated)]
109-
unsafe { ::std::mem::uninitialized() }
108+
unimplemented!()
110109
}
111110
}
112111

@@ -137,7 +136,7 @@ where
137136
{
138137
type Output = UInt<Prod<Ul, UInt<Ur, B>>, B0>;
139138
fn mul(self, _: UInt<Ur, B>) -> Self::Output {
140-
unsafe { ::std::mem::uninitialized() }
139+
unimplemented!()
141140
}
142141
}
143142

src/test/ui/abi/stack-probes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// ignore-sgx no processes
1414
// ignore-musl FIXME #31506
1515

16-
use std::mem;
16+
1717
use std::process::Command;
1818
use std::thread;
1919
use std::env;
@@ -50,8 +50,7 @@ fn main() {
5050
#[allow(unconditional_recursion)]
5151
fn recurse(array: &[u64]) {
5252
unsafe { black_box(array.as_ptr() as u64); }
53-
#[allow(deprecated)]
54-
let local: [_; 1024] = unsafe { mem::uninitialized() };
53+
let local: [u64; 1024] = [0; 1024];
5554
recurse(&local);
5655
}
5756

src/test/ui/const-generics/issues/issue-61422.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::mem;
77

88
fn foo<const SIZE: usize>() {
99
let arr: [u8; SIZE] = unsafe {
10-
#[allow(deprecated)]
11-
let array: [u8; SIZE] = mem::uninitialized();
10+
11+
let array: [u8; SIZE] = mem::zeroed();
1212
array
1313
};
1414
}

src/test/ui/for-loop-while/for-loop-has-unit-body.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
fn main() {
33
// Check that the tail statement in the body unifies with something
44
for _ in 0..3 {
5-
#[allow(deprecated)]
6-
unsafe { std::mem::uninitialized() }
5+
unsafe { std::mem::zeroed() }
76
}
87

98
// Check that the tail statement in the body can be unit

src/test/ui/issues/issue-48131.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This note is annotated because the purpose of the test
22
// is to ensure that certain other notes are not generated.
33
#![deny(unused_unsafe)] //~ NOTE
4-
#![allow(deprecated)]
4+
55

66
// (test that no note is generated on this unsafe fn)
77
pub unsafe fn a() {
@@ -21,7 +21,7 @@ pub fn b() {
2121
//~^ NOTE
2222
}
2323

24-
let () = ::std::mem::uninitialized();
24+
let () = ::std::mem::zeroed();
2525

2626
inner()
2727
}

src/test/ui/issues/issue-58212.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// run-pass
1+
// check-pass
22

33
trait FromUnchecked {
44
unsafe fn from_unchecked();
55
}
66

77
impl FromUnchecked for [u8; 1] {
88
unsafe fn from_unchecked() {
9-
#[allow(deprecated)]
10-
let mut array: Self = std::mem::uninitialized();
9+
let mut array: Self = std::mem::zeroed();
1110
let _ptr = &mut array as *mut [u8] as *mut u8;
1211
}
1312
}

src/test/ui/structs-enums/enum-non-c-like-repr-c-and-int.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ fn main() {
6969
unsafe {
7070
// This should be safe, because we don't match on it unless it's fully formed,
7171
// and it doesn't have a destructor.
72-
#[allow(deprecated)]
73-
let mut dest: MyEnum = mem::uninitialized();
72+
let mut dest: MyEnum = mem::zeroed();
7473
while buf.len() > 0 {
7574
match parse_my_enum(&mut dest, &mut buf) {
7675
Ok(()) => output.push(Ok(dest)),

0 commit comments

Comments
 (0)