-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
I-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 appliedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion
Description
Using the following flags
--force-warn clippy::useless_conversion
this code:
fn main() {
macro_rules! mac {
(iter $e:expr) => { $e.iter() };
(into_iter $e:expr) => { $e.into_iter() };
(next $e:expr) => { $e.iter().next() };
}
for _ in dbg!([1, 2]).iter() {}
for _ in mac!(iter [1, 2]).into_iter() {}
for _ in mac!(iter [1, 1]) {}
for _ in mac!(into_iter [1, 2]) {}
for _ in mac!(next [1, 2]) {}
}caused the following diagnostics:
Checking _3582410b746c0b3dac91c960e333746bbafba6e2 v0.1.0 (/tmp/icemaker_global_tempdir.fzTw1TOrsbiL/icemaker_clippyfix_tempdir.Sv6okqIuNw19/_3582410b746c0b3dac91c960e333746bbafba6e2)
warning: useless conversion to the same type: `std::slice::Iter<'_, i32>`
--> src/main.rs:9:14
|
9 | for _ in mac!(iter [1, 2]).into_iter() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `$e.iter()`
|
= 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: `_3582410b746c0b3dac91c960e333746bbafba6e2` (bin "_3582410b746c0b3dac91c960e333746bbafba6e2") generated 1 warning (run `cargo clippy --fix --bin "_3582410b746c0b3dac91c960e333746bbafba6e2" -p _3582410b746c0b3dac91c960e333746bbafba6e2` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.23s
However after applying these diagnostics, the resulting code:
fn main() {
macro_rules! mac {
(iter $e:expr) => { $e.iter() };
(into_iter $e:expr) => { $e.into_iter() };
(next $e:expr) => { $e.iter().next() };
}
for _ in dbg!([1, 2]).iter() {}
for _ in $e.iter() {}
for _ in mac!(iter [1, 1]) {}
for _ in mac!(into_iter [1, 2]) {}
for _ in mac!(next [1, 2]) {}
}no longer compiled:
Checking _3582410b746c0b3dac91c960e333746bbafba6e2 v0.1.0 (/tmp/icemaker_global_tempdir.fzTw1TOrsbiL/icemaker_clippyfix_tempdir.Sv6okqIuNw19/_3582410b746c0b3dac91c960e333746bbafba6e2)
error: expected expression, found `$`
--> src/main.rs:9:14
|
9 | for _ in $e.iter() {}
| ^ expected expression
error: could not compile `_3582410b746c0b3dac91c960e333746bbafba6e2` (bin "_3582410b746c0b3dac91c960e333746bbafba6e2" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_3582410b746c0b3dac91c960e333746bbafba6e2` (bin "_3582410b746c0b3dac91c960e333746bbafba6e2") due to 1 previous error
Version:
rustc 1.93.0-nightly (f40a70d2b 2025-11-30)
binary: rustc
commit-hash: f40a70d2bcd830a4f1f8c7ca1a7f93f1d9d703d6
commit-date: 2025-11-30
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5
Metadata
Metadata
Assignees
Labels
I-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 appliedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion