Open nabilwadih opened 1 year ago
Sample Code: go to https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b and run clippy.
#![warn(clippy::indexing_slicing)] fn foo<const X: usize, Y: Fn(&[u8]) -> [u8; X]>(a: &mut [u8], y: Y) { let b = y(a); a[0..].copy_from_slice(b[0..]); }
clippy will warn for the a[0..] slice , but not for the &b[0..] slice
a[0..]
&b[0..]
indexing_slicing
Run clippy on the code from this sample: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b
I expected to see this happen: clippy should be able to detect the second slice on b and warn about it
Instead, this happened: clippy does not warn about the second slice on b
Clippy version: 0.1.68 (2023-01-18 333ee6c)
x[0..] not linting on arrays is intentional. Really this shouldn't lint for slices either as it can never panic.
x[0..]
This should, however, probably be changed to lint on x[1..] for arrays of a generic size.
x[1..]
Summary
Sample Code: go to https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b and run clippy.
clippy will warn for the
a[0..]
slice , but not for the&b[0..]
sliceLint Name
indexing_slicing
Reproducer
Run clippy on the code from this sample: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f52e65454f24681df967fd173371e07b
I expected to see this happen: clippy should be able to detect the second slice on b and warn about it
Instead, this happened: clippy does not warn about the second slice on b
Version