Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint slicing of entire slices #6519

Closed
matthiaskrgr opened this issue Dec 30, 2020 · 0 comments · Fixed by #6528
Closed

lint slicing of entire slices #6519

matthiaskrgr opened this issue Dec 30, 2020 · 0 comments · Fixed by #6528
Labels
A-lint Area: New lints

Comments

@matthiaskrgr
Copy link
Member

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;
}
@matthiaskrgr matthiaskrgr added the A-lint Area: New lints label Dec 30, 2020
@matthiaskrgr matthiaskrgr changed the title lint slicing of slices lint slicing of entire slices Dec 30, 2020
@bors bors closed this as completed in 990e2b3 Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant