Open
Description
Summary
If I have this little Rust program:
#![warn(clippy::all)]
use std::ops::Range;
const fn signature(mut n: u32) -> u32 {
let mut result = 0;
loop {
result += 1 << ((n % 10) * 4);
n /= 10;
if n == 0 { return result; }
}
}
fn main() {
const R: Range<u32> = 2 .. 7; // Input.
let g = |n, sn| R.into_iter().all(|m| signature(n * m) == sn);
let res = (1 .. u32::MAX).find(|&n| g(n, signature(n)));
assert_eq!(res, Some(142_857));
}
Clippy gives me this warning:
warning: useless conversion to the same type: `std::ops::Range<u32>`
--> src/main.rs:15:21
|
15 | let g = |n, sn| R.into_iter().all(|m| signature(n * m) == sn);
| ^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `R`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::all)]
| ^^^^^^^^^^^
= note: `#[warn(clippy::useless_conversion)]` implied by `#[warn(clippy::all)]`
But if I remove ".into_iter()" from the Rust program, the rustc compiler (1.88.0-nightly 2025-04-19) gives me:
warning: taking a mutable reference to a `const` item
--> ...\bug1.rs:15:21
|
15 | let g = |n, sn| R.all(|m| signature(n * m) == sn);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: each usage of a `const` item creates a new temporary
= note: the mutable reference will refer to this temporary, not the original `const` item
note: mutable reference created due to call to this method
--> /rustc/077cedc2afa8ac0b727b7a6cbe012940ba228deb\library\core\src\iter\traits\iterator.rs:2719:5
note: `const` item defined here
--> ...\bug1.rs:14:5
|
14 | const R: Range<u32> = 2 .. 7; // Input.
| ^^^^^^^^^^^^^^^^^^^
= note: `#[warn(const_item_mutation)]` on by default
Lint Name
No response
Reproducer
I tried this code:
<code>
I saw this happen:
<output>
I expected to see this happen:
Version
Additional Labels
No response