Initial implementation of redundant_slicing lint

This commit is contained in:
Jason Newcomb 2020-12-31 11:10:13 -05:00
parent 3577cf79de
commit 837bc99065
No known key found for this signature in database
GPG key ID: DA59E8643A37ED06
5 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,11 @@
#![allow(unused)]
#![warn(clippy::redundant_slicing)]
fn main() {
let x: &[u32] = &[0];
let err = &x[..];
let v = vec![0];
let ok = &v[..];
let err = &(&v[..])[..];
}

View file

@ -0,0 +1,16 @@
error: redundant slicing of the whole range
--> $DIR/redundant_slicing.rs:6:15
|
LL | let err = &x[..];
| ^^^^^^ help: use the original slice instead: `x`
|
= note: `-D clippy::redundant-slicing` implied by `-D warnings`
error: redundant slicing of the whole range
--> $DIR/redundant_slicing.rs:10:15
|
LL | let err = &(&v[..])[..];
| ^^^^^^^^^^^^^ help: use the original slice instead: `(&v[..])`
error: aborting due to 2 previous errors