Rust-clippy: same_item_push being suggested for values that are not Copy or Clone

Created on 28 Aug 2020  路  1Comment  路  Source: rust-lang/rust-clippy

Similar to #5902 but instead of a mutated value, it's suggesting it for a value that is not Copy nor Clone.

Silly example:

fn main() {
    let mut vec = vec![];
    for _ in 0 .. 10 {
        vec.push(std::fs::File::open("foobar").unwrap());
    }
}

This gives the warning:

warning: it looks like the same item is being pushed into this Vec
 --> src/main.rs:4:9
  |
4 |         vec.push(std::fs::File::open("foobar").unwrap());
  |         ^^^
  |
  = note: `#[warn(clippy::same_item_push)]` on by default
  = help: try using vec![std::fs::File::open("foobar").unwrap();SIZE] or vec.resize(NEW_SIZE, std::fs::File::open("foobar").unwrap())
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push

Note the suggested replacements don't even compile.

Meta

  • cargo clippy -V: clippy 0.0.212 (397b390cc 2020-08-27)
  • rustc -Vv:
    rustc 1.48.0-nightly (397b390cc 2020-08-27) binary: rustc commit-hash: 397b390cc76ba1d98f80b2a24a371f708dcc9169 commit-date: 2020-08-27 host: x86_64-pc-windows-msvc release: 1.48.0-nightly LLVM version: 11.0
A-suggestion L-bug L-enhancement good-first-issue

Most helpful comment

I will prepare a fix.

>All comments

I will prepare a fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanmai-NL picture sanmai-NL  路  23Comments

kevincox picture kevincox  路  17Comments

dtolnay picture dtolnay  路  20Comments

davemilter picture davemilter  路  18Comments

durka picture durka  路  17Comments