File tree Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 1- #![ allow( deprecated, invalid_value) ]
2- #![ warn( clippy:: all ) ]
1+ #![ allow( deprecated, invalid_value, clippy :: uninit_assumed_init ) ]
2+ #![ warn( clippy:: mem_replace_with_uninit ) ]
33
44use std:: mem;
55
Original file line number Diff line number Diff line change @@ -12,14 +12,6 @@ error: replacing with `mem::MaybeUninit::uninit().assume_init()`
1212LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)`
1414
15- error: this call for this type may be undefined behavior
16- --> $DIR/repl_uninit.rs:21:44
17- |
18- LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
19- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20- |
21- = note: `-D clippy::uninit-assumed-init` implied by `-D warnings`
22-
2315error: replacing with `mem::zeroed()`
2416 --> $DIR/repl_uninit.rs:27:23
2517 |
@@ -34,5 +26,5 @@ error: replacing with `mem::uninitialized()`
3426LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) };
3527 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)`
3628
37- error: aborting due to 5 previous errors
29+ error: aborting due to 4 previous errors
3830
Original file line number Diff line number Diff line change 11#![ feature( stmt_expr_attributes) ]
22
3- use std:: mem:: MaybeUninit ;
3+ use std:: mem:: { self , MaybeUninit } ;
44
55fn main ( ) {
66 let _: usize = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
@@ -19,4 +19,7 @@ fn main() {
1919
2020 // This is OK, because all constitutent types are uninit-compatible.
2121 let _: ( MaybeUninit < usize > , [ MaybeUninit < bool > ; 2 ] ) = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
22+
23+ // Was a false negative.
24+ let _: usize = unsafe { mem:: MaybeUninit :: uninit ( ) . assume_init ( ) } ;
2225}
Original file line number Diff line number Diff line change @@ -12,5 +12,11 @@ error: this call for this type may be undefined behavior
1212LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
15- error: aborting due to 2 previous errors
15+ error: this call for this type may be undefined behavior
16+ --> $DIR/uninit.rs:24:29
17+ |
18+ LL | let _: usize = unsafe { mem::MaybeUninit::uninit().assume_init() };
19+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+ error: aborting due to 3 previous errors
1622
You can’t perform that action at this time.
0 commit comments