-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
Clippy 1.63 fails to detect vec-init-then-push but it is detected with 1.62. This seems to only happen when there is an if
statement after the initial push that conditionally pushes a subsequent element to the vec.
Lint Name
vec-init-then-push
Reproducer
I tried this code:
fn main() {
let vec = vec_init_then_push(false);
dbg!(vec);
}
fn vec_init_then_push(some_condition: bool) -> Vec<usize> {
let mut vec = Vec::new();
vec.push(1);
if some_condition {
vec.push(2);
}
vec
}
I expected to see this happen:
cargo clippy -- -D warnings
Checking bad-clippy v0.1.0 (/Users/junglie85/bad-clippy)
error: calls to `push` immediately after creation
--> src/main.rs:7:5
|
7 | / let mut vec = Vec::new();
8 | | vec.push(1);
| |________________^ help: consider using the `vec![]` macro: `let mut vec = vec![..];`
|
= note: `-D clippy::vec-init-then-push` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push
error: could not compile `bad-clippy` due to previous error
Instead, this happened:
cargo clippy -- -D warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.14s
Version
False negative:
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5
Detects:
rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: aarch64-apple-darwin
release: 1.62.1
LLVM version: 14.0.5
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't