Skip to content

unused_imports false positive #120422

Closed
Closed
@Kixunil

Description

@Kixunil

Code

#![no_std]

#[cfg(feature = "alloc")]
#[macro_use]
extern crate alloc;

#[cfg(test)]
mod test {
    #[test]
    #[cfg(feature = "alloc")]
    fn test() {
        format!("foo");
    }
}

Current output

warning: unused `#[macro_use]` import
 --> src/lib.rs:4:1
  |
4 | #[macro_use]
  | ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Desired output

No warning.

Rationale and extra context

#[macro_use] is actually used. When I removed it I get compilation failure. And while it can be argued, this is not the best style and use alloc::format; is better, the lint should say it if it's the case. (But really, I think this belongs to clippy, not rustc.)

Other cases

No response

Rust Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
rustc 1.77.0-nightly (5bd5d214e 2024-01-25)
binary: rustc
commit-hash: 5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c
commit-date: 2024-01-25
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6


### Anything else?

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions