Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wfraser opened this issue Aug 28, 2020 · 1 comment · Fixed by #5997
Closed

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

wfraser opened this issue Aug 28, 2020 · 1 comment · Fixed by #5997
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@wfraser
Copy link

wfraser commented Aug 28, 2020

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
@wfraser wfraser added the C-bug Category: Clippy is not doing the correct thing label Aug 28, 2020
@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Aug 31, 2020
@giraffate
Copy link
Contributor

I will prepare a fix.

@ebroto ebroto added good-first-issue These issues are a good way to get started with Clippy and removed good-first-issue These issues are a good way to get started with Clippy labels Sep 4, 2020
@bors bors closed this as completed in e9440cb Sep 5, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 1, 2020
[beta][clippy] backport multiple FP fixes for a warn-by-default lint

This backports the PR rust-lang/rust-clippy#6016 fixing multiple FPs:

rust-lang/rust-clippy#5902
rust-lang/rust-clippy#5979
rust-lang/rust-clippy#5985

We didn't have any complaints about this lint, since me merged this PR.

cc `@ebroto` (sorry I forgot about this, since we talked about the backport 3 weeks ago 😐)

r? `@pietroalbini`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants