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

cargo clippy shows no warnings, but cargo clippy --fix fails ("failed to automatically apply fixes") #113025

Open
Trolldemorted opened this issue Jun 25, 2023 · 3 comments
Labels
A-clippy Area: Clippy C-bug Category: This is a bug.

Comments

@Trolldemorted
Copy link
Contributor

I tried to use cargo clippy on this code: https://github.com/scfia/scfia-lib/tree/5e75b6da14cc00b925f2c83a4179b89ad85d8592

I expected to see this happen:

  • cargo clippy --fix does not fail.
  • cargo clippy --fix does not try to fix things that cargo clippy does not complain about.

Instead, this happened:

PS C:\Users\Benni\repositories\scfia-lib> cargo clippy --fix
    Checking scfia-lib v0.1.0 (C:\Users\Benni\repositories\scfia-lib)
warning: failed to automatically apply fixes suggested by rustc to crate `scfia_lib`

after fixes were automatically applied the compiler reported errors within these files:

  * src\z3_handle.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0382]: borrow of moved value: `b1`
   --> src\z3_handle.rs:485:64
    |
481 |             let b1 = z3.new_bool_concrete(true);
    |                 -- move occurs because `b1` has type `z3_handle::Z3Ast<models::riscv::rv32i::RV32iScfiaComposition>`, which does not implement the `Copy` trait
...
484 |                 let b2 = b1;
    |                          -- value moved here
485 |                 assert!(Rc::ptr_eq(&b2.z3.upgrade().unwrap(), &b1.z3.upgrade().unwrap()));
    |                                                                ^^^^^^^^^^^^^^^ value borrowed here after move
    |
help: consider cloning the value if the performance cost is acceptable
    |
484 |                 let b2 = b1.clone();
    |                            ++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.
Original diagnostics will follow.

warning: redundant clone
   --> src\z3_handle.rs:484:28
    |
484 |                 let b2 = b1.clone();
    |                            ^^^^^^^^ help: remove this
    |
note: cloned value is neither consumed nor mutated
   --> src\z3_handle.rs:484:26
    |
484 |                 let b2 = b1.clone();
    |                          ^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
    = note: `#[warn(clippy::redundant_clone)]` on by default

warning: `scfia-lib` (lib test) generated 1 warning (run `cargo clippy --fix --lib -p scfia-lib --tests` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 3.18s

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-pc-windows-msvc
release: 1.70.0
LLVM version: 16.0.2
@Trolldemorted Trolldemorted added the C-bug Category: This is a bug. label Jun 25, 2023
@matthiaskrgr
Copy link
Member

I think cargo clippy just runs the default target whereas cargo clippy --fix runs wtih --all-targets by default, so it is also going to check tests for example.

@Trolldemorted
Copy link
Contributor Author

should I open a dedicated issue for that?

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@Noratrieb
Copy link
Member

looks like clippy complaining about a redundant clone that it not redundant at all. can you open the issue on the rust-lang/clippy repository instead?

@jieyouxu jieyouxu added A-clippy Area: Clippy and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-clippy Area: Clippy C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants