rust-lang / rust-lang/rust-clippy
`items_after_statements` doesn't understand `cfg_select!`
Open
@saberoueslati is already working on this.
Since Aug 3, 2026.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The latest nightly introduced formatting support for cfg_select!, which led me to remove a bunch of extra {} in conditional blocks. Unfortunately this started triggering this lint unnecessarily.
Lint Name
items_after_statements
Reproducer
I tried this code:
cfg_select! {
unix => {
use std::os::unix::fs::FileExt;
self.file.read_exact_at(buf, offset)
}
windows => {
use std::os::windows::fs::FileExt;
// ...
I saw this happen:
warning: adding items after statements is confusing, since items exist from the start of the scope
--> crates/shared/ab-direct-io-file/src/lib.rs:384:17
|
384 | use std::os::unix::fs::FileExt;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
= note: `-W clippy::items-after-statements` implied by `-W clippy::pedantic`
= help: to override `-W clippy::pedantic` add `#[allow(clippy::items_after_statements)]`
warning: adding items after statements is confusing, since items exist from the start of the scope
--> crates/shared/ab-direct-io-file/src/lib.rs:436:17
|
436 | use std::os::unix::fs::FileExt;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
Adding extra {} helps, but rustfmt removes them automatically:
cfg_select! {
unix => {{
use std::os::unix::fs::FileExt;
self.file.read_exact_at(buf, offset)
}}
windows => {{
use std::os::windows::fs::FileExt;
// ...
I expected to see this happen:
No warnings
Version
rustc 1.99.0-nightly (11177f223 2026-08-02)
binary: rustc
commit-hash: 11177f2235f0c842b00f82c558ad9480c0c3a895
commit-date: 2026-08-02
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.