Open
Description
What it does
Lint against uses of copy_from_slice
, clone_from_slice
and swap_with_slice
that are guaranteed to panic.
This could also be made part of out_of_bounds_indexing
but there is precedent for having this be a separate, warn-by-default lint with iter_out_of_bounds
.
Advantage
- Remove code that is obviously erroneous
Drawbacks
No response
Example
The following would be linted (including the clone
and swap
versions) because it will always panic:
[1u8;10].copy_from_slice(&[1u8; 9]);
let mut a = [1u8;10];
let b = [1u8;9];
a.copy_from_slice(&b);
Ideally it would also lint cases where there is a simple slicing operation before the call:
let mut a = [1u8;10];
let b = [1u8;9];
a[..8].copy_from_slice(&b[..6]);