Closed
Description
Summary
Necessary curly braces not inserted before an unsafe
block inside a for-each
.
-D clippy::needless-for-each
implied by -D clippy::pedantic
Reproducer
I tried this code:
// Where `array` is an `&mut Vec<T>`:
array.iter().for_each(|val| unsafe {
// code goes here...
});
I expected to see this happen:
/// Notice that it automatically adds the necessary curly braces : )
help: try
|
11 ~ for val in array.iter() { unsafe {
12 + // code goes here...
13 + }}
|
Instead, this happened:
help: try
|
11 ~ for val in array.iter() unsafe {
12 + // code goes here...
13 + }
|
/// This is the error before the attempt-to-replace
The following errors were reported:
error: expected `{`, found keyword `unsafe`
--> ...
|
11 | for val in array.iter() unsafe {
| ^^^^^^ expected `{`
|
help: try placing this code inside a block
|
11 ~ for val in array.iter() { unsafe {
12 | // code goes here...
13 ~ } }
|
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-gnu
release: 1.76.0
LLVM version: 17.0.6
Additional Labels
@rustbot label +l-suggestion-causes-error