Closed
Description
What it does
In code like this
fn a(v: &Vec<String>) {
let _get_me_a_slice: &[String] = &v[..];
}
clippy will suggest passing v as slice instead of Vec
, resulting in this refactoring:
fn a(v: &[String]) {
let _get_me_a_slice: &[String] = &v[..];
}
But this means we are slicing the slice to get a slice, we can remove the [..]
now!
fn a(v: &[String]) {
let _get_me_a_slice: &[String] = v;
}
It would be nice if clippy could warn about slicing of slices.
Categories (optional)
Kind: complexity?
What is the advantage of the recommended code over the original code
Simple code
Drawbacks
None.
Example
fn a(v: &[String]) {
let _slice: &[String] = &v[..];
}
Could be written as:
fn a(v: &[String]) {
let _slice: &[String] = v;
}