rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.44k stars 12.73k forks source link

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

Open Trolldemorted opened 1 year ago

Trolldemorted commented 1 year ago

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

I expected to see this happen:

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
matthiaskrgr commented 1 year ago

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 commented 1 year ago

should I open a dedicated issue for that?

Noratrieb commented 1 year ago

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?