Skip to content

New lint: slow or unsafe vector initialization #3237

Closed
@ishitatsuyuki

Description

@ishitatsuyuki

Cross post of rust-lang/rust#54628. See the thread for more details. The content below is a dumb summary.

Bad example

// resize
let mut vec1 = Vec::with_capacity(len);
vec1.resize(len, 0);
// extend
let mut vec2 = Vec::with_capacity(len);
vec2.extend(repeat(0).take(len))

Also some unsafe approaches exist, but it's TBD.

Good example

// vec! macro
let mut vec3 = vec![0; len];

Metadata

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