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

slow_vector_initialization should catch capacity call #8800

Closed
nazar-pc opened this issue May 8, 2022 · 1 comment · Fixed by #8953
Closed

slow_vector_initialization should catch capacity call #8800

nazar-pc opened this issue May 8, 2022 · 1 comment · Fixed by #8953
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@nazar-pc
Copy link

nazar-pc commented May 8, 2022

Summary

Call to capacity is DRY approach to fill pre-allocated vector and should be treated the same way as explicit length

Lint Name

slow_vector_initialization

Reproducer

I tried this code:

let mut vec1 = Vec::with_capacity(len);
vec1.resize(vec1.capacity(), 0);

I expected to see this happen:

14 |     let mut vec1 = Vec::with_capacity(len);
   |                    ----------------------- help: consider replace allocation with: `vec![0; len]`
15 |     vec1.resize(vec1.capacity(), 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::slow_vector_initialization)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization

Instead, this happened:
No warning

Version

rustc 1.60.0-nightly (c5c610aad 2022-02-14)
binary: rustc
commit-hash: c5c610aad0a012a9228ecb83cc19e77111a52140
commit-date: 2022-02-14
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
@nazar-pc nazar-pc added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels May 8, 2022
@DevAccentor
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants