Skip to content

False warning: unnecessary use of cloned #16212

@andyquinterom

Description

@andyquinterom

Summary

warning: failed to automatically apply fixes suggested by rustc to crate `dispenser`

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

  * src/main.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-clippy/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[E0597]: `instances.inner` does not live long enough
  --> src/main.rs:53:25
   |
46 |           let instances = instances.lock().await.clone();
   |               --------- binding `instances` declared here
...
53 |           for instance in instances.inner.iter() {
   |                           ^^^^^^^^^^^^^^^ borrowed value does not live long enough
54 | /             tokio::spawn(async move {
55 | |                 instance.lock().await.poll(poll_images).await;
56 | |             });
   | |______________- argument requires that `instances.inner` is borrowed for `'static`
57 |           }
58 |       }
   |       - `instances.inner` dropped here while still borrowed

error: aborting due to 1 previous error

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

warning: unnecessary use of `cloned`
  --> src/main.rs:53:25
   |
53 |         for instance in instances.inner.iter().cloned() {
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove any references to the binding: `instances.inner.iter()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#unnecessary_to_owned
   = note: `#[warn(clippy::unnecessary_to_owned)]` on by default

warning: `dispenser` (bin "dispenser") generated 1 warning (run `cargo clippy --fix --bin "dispenser"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s

Lint Name

unnecessary_to_owned

Reproducer

I tried this code:

<code>

I saw this happen:

<output>

I expected to see this happen:

Version


Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions