rust-lang / rust-lang/rust-clippy

cargo clippy --fix produced uncompilable code

Open
#8,458 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by checking out c197141 in geo and running cargo clippy --fix, then inspect the manual_map suggestion involving geo/src/algorithm/concave_hull.rs:153. Determine how the suggestion leads to E0505, and validate that the corrected behavior no longer applies an uncompilable change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.