rust-lang / rust-lang/rust-clippy

`useless_conversion` causes syntax error

Open
#16,010 2 comments 0 reactions 1 assignee View on GitHub

@ada4a is already working on this.

Since Nov 5, 2025.

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

Description

Using the following flags

--force-warn clippy::useless_conversion

this code:

use std::marker::PhantomData;

struct ExtendRef<'a, T, E: Extend<T>> {
    extend: &'a mut E,
    _phantom: PhantomData<T>,
}

impl<'a, T, E: Extend<T>> ExtendRef<'a, T, E> {
    pub fn new(extend: &'a mut E) -> Self {
        Self {
            extend,
            _phantom: PhantomData,
        }
    }
}

impl<'a, T, E: Extend<T>> Extend<T> for ExtendRef<'a, T, E> {
    fn extend<I>(&mut self, iter: I)
    where
        I: IntoIterator<Item = T>
    {
        self.extend.extend(iter);
    }
}

fn main() {
    let mut v0 = Vec::new();
    let mut v1 = Vec::new();
    
    (ExtendRef::new(&mut v0), ExtendRef::new(&mut v1)).extend(
        (0..10).into_iter()
            .zip((0..10).into_iter())
    );
}

caused the following diagnostics:

    Checking _3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb v0.1.0 (/tmp/icemaker_global_tempdir.tMrpGeJ6WWUI/icemaker_clippyfix_tempdir.f2zO6RE0wxoq/_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb)
warning: useless conversion to the same type: `std::ops::Range<i32>`
  --> src/main.rs:31:9
   |
31 |         (0..10).into_iter()
   |         ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `(0..10)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
   = note: requested on the command line with `--force-warn clippy::useless-conversion`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
   --> src/main.rs:32:18
    |
 32 |             .zip((0..10).into_iter())
    |                  ^^^^^^-------------
    |                        |
    |                        help: consider removing the `.into_iter()`
    |
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
   --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:616:12
    |
616 |         U: IntoIterator,
    |            ^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

warning: `_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb` (bin "_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb") generated 2 warnings (run `cargo clippy --fix --bin "_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb" -p _3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s

However after applying these diagnostics, the resulting code:

use std::marker::PhantomData;

struct ExtendRef<'a, T, E: Extend<T>> {
    extend: &'a mut E,
    _phantom: PhantomData<T>,
}

impl<'a, T, E: Extend<T>> ExtendRef<'a, T, E> {
    pub fn new(extend: &'a mut E) -> Self {
        Self {
            extend,
            _phantom: PhantomData,
        }
    }
}

impl<'a, T, E: Extend<T>> Extend<T> for ExtendRef<'a, T, E> {
    fn extend<I>(&mut self, iter: I)
    where
        I: IntoIterator<Item = T>
    {
        self.extend.extend(iter);
    }
}

fn main() {
    let mut v0 = Vec::new();
    let mut v1 = Vec::new();
    
    (ExtendRef::new(&mut v0), ExtendRef::new(&mut v1)).extend(
        (0..10)
            .zip((0..10)
    );
}

no longer compiled:

    Checking _3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb v0.1.0 (/tmp/icemaker_global_tempdir.tMrpGeJ6WWUI/icemaker_clippyfix_tempdir.f2zO6RE0wxoq/_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb)
error: mismatched closing delimiter: `}`
  --> src/main.rs:30:62
   |
26 | fn main() {
   |           - closing delimiter possibly meant for this
...
30 |     (ExtendRef::new(&mut v0), ExtendRef::new(&mut v1)).extend(
   |                                                              ^ unclosed delimiter
...
34 | }
   | ^ mismatched closing delimiter

error: could not compile `_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb` (bin "_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb` (bin "_3ca821fa99d08cef95e4f2b362edafdb1ed6b5fb") due to 1 previous error

Version:

rustc 1.93.0-nightly (6a884ad1b 2025-11-02)
binary: rustc
commit-hash: 6a884ad1b502fe48307d363858510702429fc735
commit-date: 2025-11-02
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.