Closed
Description
I tried this code:
fn main() {
let v1 = vec![Some(1), Some(2), Some(3), None];
let mut v1_iter = v1.iter();
let mut v2 = Vec::new();
for _ in 0..3 {
let a = match v1_iter.next() {
Some(a) => a,
None => break,
};
v2.push(a);
}
println!("items are not the same: {:#?}", v2);
}
I expected to see this happen:
No warnings.
Instead, this happened:
Clippy warns:
warning: it looks like the same item is being pushed into this Vec
--> src/main.rs:10:9
|
10 | v2.push(a);
| ^^
|
= note: `#[warn(clippy::same_item_push)]` on by default
= help: try using vec![a;SIZE] or v2.resize(NEW_SIZE, a)
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
warning: 1 warning emitted
Meta
cargo clippy -V
: clippy 0.0.212 (7e6d6e5 2020-08-16)rustc -Vv
:
rustc 1.47.0-nightly (7e6d6e5f5 2020-08-16)
binary: rustc
commit-hash: 7e6d6e5f535321c2223f044caba16f97b825009c
commit-date: 2020-08-16
host: x86_64-apple-darwin
release: 1.47.0-nightly
LLVM version: 10.0
Backtrace
<backtrace>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment