Skip to content

same_item_push being suggested for values that are not Copy or Clone #5979

Closed
@wfraser

Description

@wfraser

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 (397b390 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions