Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Missing { … } for needless_for_each #14734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
madonuko opened this issue May 4, 2025 · 1 comment · May be fixed by #14735
Open

Missing { … } for needless_for_each #14734

madonuko opened this issue May 4, 2025 · 1 comment · May be fixed by #14735
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@madonuko
Copy link

madonuko commented May 4, 2025

Summary

Clippy forgot about the {} for the suggestions.

Reproducer

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=3dedb348e9d9b077d3bcaa43ff1bc346

const LANGUAGE_ROWS: [u8; 0] = [];

#[warn(clippy::needless_for_each)]
fn main() {
    let mut v = vec![];
    LANGUAGE_ROWS.iter().for_each(|x| _ = v.push(x));
}
    Checking playground v0.0.1 (/playground)
warning: needless use of `for_each`
 --> src/main.rs:6:5
  |
6 |     LANGUAGE_ROWS.iter().for_each(|x| _ = v.push(x));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in LANGUAGE_ROWS.iter() _ = v.push(x)`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
note: the lint level is defined here
 --> src/main.rs:3:8
  |
3 | #[warn(clippy::needless_for_each)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: this let-binding has unit value
 --> src/main.rs:6:39
  |
6 |     LANGUAGE_ROWS.iter().for_each(|x| _ = v.push(x));
  |                                       ^^^^^^^^^^^^^ help: omit the `let` binding: `v.push(x);`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
  = note: `#[warn(clippy::let_unit_value)]` on by default

warning: `playground` (bin "playground") generated 2 warnings (run `cargo clippy --fix --bin "playground"` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.75s

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

@madonuko madonuko added the C-bug Category: Clippy is not doing the correct thing label May 4, 2025
@Alexendoo Alexendoo added L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels May 4, 2025
@profetia
Copy link
Contributor

profetia commented May 5, 2025

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants