-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4479 - rust-lang:uninit_assume_init, r=flip1995
lint against `MaybeUninit::uninit().assume_init()` changelog: add `uninit_assumed_init` lint This fixes #4272
- Loading branch information
Showing
8 changed files
with
118 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![feature(stmt_expr_attributes)] | ||
|
||
use std::mem::MaybeUninit; | ||
|
||
#[allow(clippy::let_unit_value)] | ||
fn main() { | ||
let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ||
|
||
// edge case: For now we lint on empty arrays | ||
let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() }; | ||
|
||
// edge case: For now we accept unit tuples | ||
let _: () = unsafe { MaybeUninit::uninit().assume_init() }; | ||
|
||
// This is OK, because `MaybeUninit` allows uninitialized data. | ||
let _: MaybeUninit<usize> = unsafe { MaybeUninit::uninit().assume_init() }; | ||
|
||
// This is OK, because all constitutent types are uninit-compatible. | ||
let _: (MaybeUninit<usize>, MaybeUninit<bool>) = unsafe { MaybeUninit::uninit().assume_init() }; | ||
|
||
// This is OK, because all constitutent types are uninit-compatible. | ||
let _: (MaybeUninit<usize>, [MaybeUninit<bool>; 2]) = unsafe { MaybeUninit::uninit().assume_init() }; | ||
} |
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,16 @@ | ||
error: this call for this type may be undefined behavior | ||
--> $DIR/uninit.rs:7:29 | ||
| | ||
LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[deny(clippy::uninit_assumed_init)]` on by default | ||
|
||
error: this call for this type may be undefined behavior | ||
--> $DIR/uninit.rs:10:31 | ||
| | ||
LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|