-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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".
- Loading branch information
1 parent
3982d35
commit c205f6a
Showing
15 changed files
with
81 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use std::mem::MaybeUninit; | ||
|
||
fn main() { | ||
// This is technically not sound -- but we're literally trying to test | ||
// that the sanitizer catches this, so I guess "intentionally unsound"? | ||
let xs: [u8; 4] = unsafe { MaybeUninit::uninit().assume_init() }; | ||
let y = xs[0] + xs[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use std::mem; | ||
|
||
fn main() { | ||
// This is technically not sound -- but we're literally trying to test | ||
// that the sanitizer catches this, so I guess "intentionally unsound"? | ||
#[allow(deprecated)] | ||
let xs: [u8; 4] = unsafe { mem::uninitialized() }; | ||
let xs: [u8; 4] = unsafe { std::mem::uninitialized() }; | ||
let y = xs[0] + xs[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
// run-pass | ||
// build-pass | ||
// Test the uninit() construct returning various empty types. | ||
|
||
// pretty-expanded FIXME #23616 | ||
|
||
use std::mem; | ||
use std::mem::MaybeUninit; | ||
|
||
#[derive(Clone)] | ||
struct Foo; | ||
|
||
#[allow(deprecated)] | ||
pub fn main() { | ||
unsafe { | ||
let _x: Foo = mem::uninitialized(); | ||
let _x: [Foo; 2] = mem::uninitialized(); | ||
// `Foo` and `[Foo; 2]` are both zero sized and inhabited, so this is safe. | ||
let _x: Foo = MaybeUninit::uninit().assume_init(); | ||
let _x: [Foo; 2] = MaybeUninit::uninit().assume_init(); | ||
let _x: Foo = std::mem::uninitialized(); | ||
let _x: [Foo; 2] = std::mem::uninitialized(); | ||
} | ||
} |