rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.44k stars 1.54k forks source link

cargo clippy --fix produced uncompilable code #8458

Open nyurik opened 2 years ago

nyurik commented 2 years ago

Per instructions in cargo clippy --fix, posting a bug. The same bug shows up when using the latest 1.61.0-nightly (03a8cc7df 2022-02-21)

warning: failed to automatically apply fixes suggested by rustc to crate `geo`
after fixes were automatically applied the compiler reported errors within these files:
...
The following errors were reported:
error[E0505]: cannot move out of `edges_nearby_point` because it is borrowed
   --> geo/src/algorithm/concave_hull.rs:153:55

To reproduce:

git clone https://github.com/georust/geo.git && \
cd geo && \
git checkout c197141 && \
cargo clippy --fix  

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
Full error report

``` warning: failed to automatically apply fixes suggested by rustc to crate `geo` after fixes were automatically applied the compiler reported errors within these files: * geo/src/algorithm/concave_hull.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[E0505]: cannot move out of `edges_nearby_point` because it is borrowed --> geo/src/algorithm/concave_hull.rs:153:55 | 152 | let peeked_edge = edges_nearby_point.peek(); | ------------------------- borrow of `edges_nearby_point` occurs here 153 | let closest_edge_option = peeked_edge.map(|&edge| edges_nearby_point.fold(*edge, |acc, candidate| { | --- ^^^^^^^ ------------------ move occurs due to use in closure | | | | | move out of `edges_nearby_point` occurs here | borrow later used by call error: aborting due to previous error For more information about this error, try `rustc --explain E0505`. Original diagnostics will follow. warning: manual implementation of `Option::map` --> geo/src/algorithm/concave_hull.rs:153:39 | 153 | let closest_edge_option = match peeked_edge { | _______________________________________^ 154 | | None => None, 155 | | Some(&edge) => Some(edges_nearby_point.fold(*edge, |acc, candidate| { 156 | | if closest_point.euclidean_distance(&acc) ... | 163 | | })), 164 | | }; | |_____________^ | = note: `#[warn(clippy::manual_map)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_map help: try this | 153 ~ let closest_edge_option = peeked_edge.map(|&edge| edges_nearby_point.fold(*edge, |acc, candidate| { 154 + if closest_point.euclidean_distance(&acc) 155 + > closest_point.euclidean_distance(candidate) 156 + { 157 + *candidate 158 + } else { ... warning: `geo` (lib) generated 1 warning ```

Jarcho commented 2 years ago

This is the same as #8346