tikv / agatedb

A persistent key-value storage in rust.
Apache License 2.0
837 stars 77 forks source link

(clippy::uninit_assumed_init): this call for this type may be undefined behavior #105

Open pymongo opened 3 years ago

pymongo commented 3 years ago

https://github.com/tikv/agatedb/blob/4aa6420cf79c5ef1a73e346591cfe39cca3a1a15/src/value.rs#L129

should change to

let mut arr: [MaybeUninit<u8>; 12] = unsafe { MaybeUninit::uninit().assume_init() };

or

let mut arr = [0u8; 12];

error: this call for this type may be undefined behavior
   --> src/value.rs:129:42
    |
129 |         let mut arr: [u8; 12] = unsafe { MaybeUninit::uninit().assume_init() };
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[deny(clippy::uninit_assumed_init)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
BusyJay commented 3 years ago

I think it's over-warning in this specific case. u8 is never read from and it doesn't implement Drop, it should be safe to assume init. But I'm also OK to change it to meet best practice.