Fix false positive of useless_conversion when using .into_iter().any() (#14800)

Fixes: rust-lang/rust-clippy#14656

changelog: Fix [`useless_conversion`] false positive when using
`.into_iter().any()`.
This commit is contained in:
llogiq 2025-05-16 06:49:42 +00:00 committed by GitHub
commit ff5e626837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 71 additions and 2 deletions

View file

@ -427,3 +427,18 @@ mod issue11819 {
}
}
}
fn issue14739() {
use std::ops::Range;
const R: Range<u32> = 2..7;
R.into_iter().all(|_x| true); // no lint
R.into_iter().any(|_x| true); // no lint
R.for_each(|_x| {});
//~^ useless_conversion
let _ = R.map(|_x| 0);
//~^ useless_conversion
}

View file

@ -427,3 +427,18 @@ mod issue11819 {
}
}
}
fn issue14739() {
use std::ops::Range;
const R: Range<u32> = 2..7;
R.into_iter().all(|_x| true); // no lint
R.into_iter().any(|_x| true); // no lint
R.into_iter().for_each(|_x| {});
//~^ useless_conversion
let _ = R.into_iter().map(|_x| 0);
//~^ useless_conversion
}

View file

@ -377,5 +377,17 @@ LL - takes_into_iter(self.my_field.into_iter());
LL + takes_into_iter(&mut *self.my_field);
|
error: aborting due to 41 previous errors
error: useless conversion to the same type: `std::ops::Range<u32>`
--> tests/ui/useless_conversion.rs:440:5
|
LL | R.into_iter().for_each(|_x| {});
| ^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `R`
error: useless conversion to the same type: `std::ops::Range<u32>`
--> tests/ui/useless_conversion.rs:442:13
|
LL | let _ = R.into_iter().map(|_x| 0);
| ^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `R`
error: aborting due to 43 previous errors