Skip to content

wrong hint about removing .into_iter() in zip #11819

@borisfaure

Description

@borisfaure

Summary

I tried running cargo clippy --fix on https://github.com/TeXitoi/keyberon but I got the following issue.

 cargo clippy --fix --lib -p keyberon                                                                                                                                                                                                                                                                                  
    Checking keyberon v0.2.0 (/home/boris/stuff/kb/keyberon)
warning: failed to automatically apply fixes suggested by rustc to crate `keyberon`

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

  * /home/boris/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs
  * src/debounce.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[E0277]: `T` is not an iterator
   --> src/debounce.rs:108:22
    |
108 |                     .zip(self.cur)
    |                      ^^^ `T` is not an iterator
    |
    = note: required for `T` to implement `core::iter::IntoIterator`
help: consider further restricting this bound
    |
39  | impl<T: PartialEq + core::iter::Iterator> Debouncer<T> {
    |                   ++++++++++++++++++++++

error[E0599]: the method `enumerate` exists for struct `Zip<<&T as IntoIterator>::IntoIter, T>`, but its trait bounds were not satisfied
   --> src/debounce.rs:109:22
    |
106 | /                 self.new
107 | |                     .into_iter()
108 | |                     .zip(self.cur)
109 | |                     .enumerate()
    | |                     -^^^^^^^^^ method cannot be called on `Zip<<&T as IntoIterator>::IntoIter, T>` due to unsatisfied trait bounds
    | |_____________________|
    |
    |
   ::: /home/boris/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/zip.rs:13:1
    |
13  |   pub struct Zip<A, B> {
    |   -------------------- doesn't satisfy `_: Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `T: core::iter::Iterator`
            which is required by `core::iter::Zip<<&'a T as core::iter::IntoIterator>::IntoIter, T>: core::iter::Iterator`
            `core::iter::Zip<<&'a T as core::iter::IntoIterator>::IntoIter, T>: core::iter::Iterator`
            which is required by `&mut core::iter::Zip<<&'a T as core::iter::IntoIterator>::IntoIter, T>: core::iter::Iterator`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
Original diagnostics will follow.

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
   --> src/debounce.rs:108:26
    |
108 |                     .zip(self.cur.into_iter())
    |                          ^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `self.cur`
    |
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
   --> /home/boris/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:642:12
    |
642 |         U: IntoIterator,
    |            ^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
    = note: `#[warn(clippy::useless_conversion)]` on by default

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

Please note that this warning

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
   --> src/debounce.rs:111:43
    |
111 |                         o.into_iter().zip(n.into_iter()).enumerate().filter_map(
    |                                           ^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `n`
    |
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
   --> /home/boris/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:642:12
    |
642 |         U: IntoIterator,
    |            ^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

warning: `keyberon` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p keyberon` to apply 2 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 0.55s

is valid and can be fixed with the suggestion.

Lint Name

useless_conversion

Reproducer

A reproducer can be found on:
https://github.com/borisfaure/keyberon/tree/explicit_into_iter

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions