False positive for vec_init_then_push with control flow in push arg #6615
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Lint name: vec_init_then_push
Here's a simple example:
The result:
The fact that the span goes over a
loop {
is surprising, although perhaps this is the result of some compiler refactoring. The lint seems to trigger when there is complex control flow inside the argument topush
; in my real example it was avec.push(loop { ... break val })
. If not for the outerloop
this could still be refactored to avec![...]
as suggested, but with it this is definitely an incorrect suggestion. If the loop ended with abreak
I would still be inclined to consider it a false positive, because loops can hide other kinds of control flow like internal break/continue, so rather than doing a full control flow analysis it should just not trigger if the push in question is syntactically in aloop
orif
.Meta
cargo clippy -V
: clippy 0.1.51 (a4cbb44 2021-01-20)rustc -Vv
:The text was updated successfully, but these errors were encountered: