← Rule catalog

Clippy · Performance

Vec created then immediately filled with pushes

clippy::vec_init_then_push

Build the vector with the vec! literal so it is allocated once at its final size.

Category
Performance
Default level
warn
Tier
P3
Producer
Clippy
Diff scope
line

Not a defect when

The pushes are interleaved with cfg attributes or conditions that vec! cannot express, or the vector is preallocated with with_capacity for growth beyond these elements.

What it reads

Clippy, with the compiler behind it. The only pass that compiles.

Tier

Lowest tier: real, and rarely urgent.

The tier bounds how severe a rule may be; its category bounds the tier.

Diff scope

The changed line itself.

What --scope contextual looks at to decide whether a change caused the finding.

Change it

Turn it off, or make it blocking, without touching the code it flags:

rust-doctor --rule clippy::vec_init_then_push=off .
rust-doctor --rule clippy::vec_init_then_push=error .

Set it once in rust-doctor.toml

Upstream

Clippy's own documentation for this lint

Other Performance rules