getditto/safer_ffi

Clippy reports `size_of_in_element_count` lint errors in the generated code from derive_ReprC macro

Opened this issue · 2 comments

截圖 2022-09-03 下午10 54 34

The link of this lint rule is https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count.

Not sure if this is supposed to do, as the documentation of std::slice::from_raw_parts indicates that the len parameter of it is the number of elements, not the number of bytes.

If it is supposed to do, how about to allow this lint rule with #[allow(clippy::size_of_in_element_count)]?

The code linted by this is really debugging code (correct code ought never to run into it); while the lint itself is a false positive (I'll have it silenced before the next release), it is true that it does something unorthodox: it reinterprets a type as its raw bytes, potentially exposing padding or uninit bytes, which is not great. So, all in all, I guess I could (default) feature-gate this snippet so that people can disable it