-
Couldn't load subscription status.
- Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
When using a multi-line closure in a method call (e.g. for_each(|x| { ... })),
Clippy’s semicolon_if_nothing_returned lint reports the correct warning but displays an incorrect line number in its diagnostic output.
Reproducer
I tried this code:
fn foo(nums: Vec<u32>) {
nums.iter().for_each(|x| {
if *x > 0 {
println!("Positive number");
} else {
println!("Negative number");
}
})
}
fn main() {
let nums = vec![1, 2, 3, 4, 5];
foo(nums);
}command: cargo clippy -- -D clippy::semicolon_if_nothing_returned
I expected to see this happen:
error: consider adding a `;` to the last statement for consistent formatting
--> src\main.rs:2:5
|
2 | / nums.iter().for_each(|x| {
3 | | if *x > 0 {
4 | | println!("Positive number");
5 | | } else {
... |
8 | | })
| |______^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
= note: requested on the command line with `-D clippy::semicolon-if-nothing-returned`
help: add a `;` here
|
2 | nums.iter().for_each(|x| {
...
7| }
8~ });
|Instead, this happened:
error: consider adding a `;` to the last statement for consistent formatting
--> src\main.rs:2:5
|
2 | / nums.iter().for_each(|x| {
3 | | if *x > 0 {
4 | | println!("Positive number");
5 | | } else {
... |
8 | | })
| |______^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
= note: requested on the command line with `-D clippy::semicolon-if-nothing-returned`
help: add a `;` here
|
8 | nums.iter().for_each(|x| {
...
13| }
14~ });
|Version
rustc 1.92.0-nightly (3d8c1c1fc 2025-10-06)
binary: rustc
commit-hash: 3d8c1c1fc077d04658de63261d8ce2903546db13
commit-date: 2025-10-06
host: x86_64-pc-windows-msvc
release: 1.92.0-nightly
LLVM version: 21.1.2
clippy 0.1.92 (3d8c1c1fc0 2025-10-06)
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing