-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied