Closed
Description
What it does
When a
is &[T]
, detect a.len() * size_of::<T>()
and suggest size_of_val(a)
instead.
Lint Name
manual_slice_size_calculation
Category
complexity, perf
Advantage
- Shorter to write
- Removes the need for the human and the compiler to worry about overflow in the multiplication
- Potentially faster at runtime as rust emits special no-wrapping flags when it calculates the byte length
- Less turbofishing
Drawbacks
No response
Example
let newlen = data.len() * mem::size_of::<$ty>();
Could be written as:
let newlen = mem::size_of_val(data);