Skip to content

Prefer vec.truncate(x) over vec.drain(x..) #13580

Open

Description

What it does

Suggest to replace vec.drain(x..) to vec.truncate(x) since it is simpler and cleaner.

Advantage

  • It is shorter and cleaner

Drawbacks

No response

Example

fn main() {
    let mut x = vec![1, 2, 3, 4, 5, 6];
    x.drain(1..);
}

Could be written as:

fn main() {
    let mut x = vec![1, 2, 3, 4, 5, 6];
    x.truncate(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions