RS.CLIPPY.SIZE_OF_IN_ELEMENT_COUNT
Using `size_of::<T>` or `size_of_val::<T>` where a count of elements of `T` is expected
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: size_of_in_element_count. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Detects expressions where
size_of::<T> or size_of_val::<T> is used as a
count of elements of type T
Why is this bad?
These functions expect a count
of T and not a number of bytes
Example
const SIZE: usize = 128;
let x = [2u8; SIZE];
let mut y = [2u8; SIZE];
unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };