Closed
Description
Simple example:
let mut out = Vec::new();
let mut i = 0;
for _ in 0..100 {
out.push(i);
i += 10;
}
dbg!(out);
I expected to see this happen:
No clippy warning, because the value being pushed is not constant (despite the otherwise unidiomatic code, as this is a contrived example).
Instead, this happened:
The same_item_push
lint throws a warning with an incorrect description of a fix.
warning: it looks like the same item is being pushed into this Vec
--> src\main.rs:5:9
|
5 | out.push(i);
| ^^^
|
= note: `#[warn(clippy::same_item_push)]` on by default
= help: try using vec![i;SIZE] or out.resize(NEW_SIZE, i)
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
warning: 1 warning emitted
The docs at https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push say that this lint should only fire when "a for loop is used to push a constant value", but in this case the value being pushed is not constant.
Meta
cargo clippy -V
: clippy 0.0.212 (576d27c 2020-08-12)rustc -Vv
:
rustc 1.47.0-nightly (576d27c 2020-08-12)
binary: rustc
commit-hash: 576d27c
commit-date: 2020-08-12
host: x86_64-pc-windows-msvc
release: 1.47.0-nightly
LLVM version: 10.0