mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-11 07:34:18 +00:00
f6c5d8d599
Add note to fix `MATCH_TYPE_ON_DIAG_ITEM` Add false negative test for `uninit_assumed_init`
25 lines
991 B
Rust
25 lines
991 B
Rust
#![feature(stmt_expr_attributes)]
|
|
|
|
use std::mem::{self, MaybeUninit};
|
|
|
|
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() };
|
|
|
|
// Was a false negative.
|
|
let _: usize = unsafe { mem::MaybeUninit::uninit().assume_init() };
|
|
}
|