Description
Summary
This appears to be a regression; it does not happen in nightly-2024-02-18
, but happens in nightly-2024-02-19
and later (the rustc -Vv
version below)
Lint Name
unused_imports
Reproducer
I tried this code, which (in the real code) has std
-dependent functionality gated behind a feature:
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::boxed::Box;
pub fn make() -> Box<usize> {
Box::new(1)
}
As of the nightly-2024-04-19
toolchain, it now produces these errors when the std
feature is enabled, complaining that the alloc
imports are redundant:
$ cargo clippy
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
$ cargo clippy --all-features
warning: the item `Box` is imported redundantly
--> src/lib.rs:5:5
|
5 | use alloc::boxed::Box;
| ^^^^^^^^^^^^^^^^^
|
::: /home/widders/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
|
125 | pub use super::v1::*;
| --------- the item `Box` is already defined here
|
= note: `#[warn(unused_imports)]` on by default
warning: `clippytest` (lib) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
I expected to see this happen:
No warning with the feature either enabled or disabled :)
The imports it is complaining about are redundant, in theory... we could put each and every import for something that is missing in the no_std
prelude but present in the std
one behind a #[cfg(feature = "std")]
. However: this feels bad, this looks bad, and until less than a week ago it was not requested by clippy. Therefore I suspect this is a regression.
Version
rustc 1.78.0-nightly (2bf78d12d 2024-02-18)
binary: rustc
commit-hash: 2bf78d12d33ae02d10010309a0d85dd04e7cff72
commit-date: 2024-02-18
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
Additional Labels
No response