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 ) ]
3
3
4
4
use std:: mem;
5
5
Original file line number Diff line number Diff line change @@ -12,14 +12,6 @@ error: replacing with `mem::MaybeUninit::uninit().assume_init()`
12
12
LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)`
14
14
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
-
23
15
error: replacing with `mem::zeroed()`
24
16
--> $DIR/repl_uninit.rs:27:23
25
17
|
@@ -34,5 +26,5 @@ error: replacing with `mem::uninitialized()`
34
26
LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) };
35
27
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)`
36
28
37
- error: aborting due to 5 previous errors
29
+ error: aborting due to 4 previous errors
38
30
Original file line number Diff line number Diff line change 1
1
#![ feature( stmt_expr_attributes) ]
2
2
3
- use std:: mem:: MaybeUninit ;
3
+ use std:: mem:: { self , MaybeUninit } ;
4
4
5
5
fn main ( ) {
6
6
let _: usize = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
@@ -19,4 +19,7 @@ fn main() {
19
19
20
20
// This is OK, because all constitutent types are uninit-compatible.
21
21
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 ( ) } ;
22
25
}
Original file line number Diff line number Diff line change @@ -12,5 +12,11 @@ error: this call for this type may be undefined behavior
12
12
LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
14
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
16
22
You can’t perform that action at this time.
0 commit comments