Skip to content

unused_imports shouldn't fire for alloc types included in the std prelude #121362

Closed
@c410-f3r

Description

@c410-f3r

When working with libraries that can or can not be #[no_std], it is common to simply extern crate alloc; and then manually import types like alloc::vec::Vec. In this way everything works regardless of the configuration.

However, the latest versions of the compiler are warning such approach.

warning: the item Vec is imported redundantly
--> foo.rs:96:7
|
96 | use alloc::vec::Vec;
| ^^^^^^^^^^^^^^^
|
::: $HOME/.rustup/toolchains/nightly-2024-02-19-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
|
125 | pub use super::v1::*;
| --------- the item Vec is already defined here

In the above example, if use alloc::vec::Vec; is removed #[no_std] breaks. If not removed, the warning persists 😑

Maybe related: #121312 #121331 #121330 #120422

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions