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

clippy fix fails: warning: failed to automatically apply fixes suggested by rustc to crate #7392

Closed
chathaway-codes opened this issue Jun 22, 2021 · 2 comments · Fixed by #7463
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@chathaway-codes
Copy link

chathaway-codes commented Jun 22, 2021

I tried this code:

struct Player {
    hand: Vec<usize>,
}

fn main() {
    let p = Player {
        hand: vec![1, 2, 3, 4, 5],
    };
    let filter_hand = vec![5];
    let new_hand: Vec<usize> = p
        .hand
        .iter()
        .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
        .map(|c| c.clone())
        .collect();
    println!("Hello, world!");
}

(this is a reduced and largely nonsensical version of the real issue I hit)

With the command: cargo clippy --fix -Z unstable-options --allow-dirty

I expected to see this happen: Clippy cleanup the source code without error.

Instead, this happened: I got a rather long error message, [output.txt] attached.

output.txt

Meta

  • cargo clippy -V: e.g. clippy 0.0.212 (f455e46 2020-06-20)
  • rustc -Vv:
% cargo clippy -V 
clippy 0.1.54 (ce1d561 2021-06-18)
% rustc -Vv
rustc 1.55.0-nightly (ce1d5611a 2021-06-18)
binary: rustc
commit-hash: ce1d5611a28468663e275078649e7ca6eef735a8
commit-date: 2021-06-18
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1
Backtrace

N/A, no crash

@chathaway-codes
Copy link
Author

Original bug report: rust-lang/rust#86538

@giraffate giraffate added I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Jun 22, 2021
@camsteffen
Copy link
Contributor

Clippy is suggesting any(|cc| c == cc) instead of any(|cc| c == &cc). find gives a reference to the element and any does not.

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 I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants