Skip to content

unused_imports on pub use macros::* should explain that [macro_export] macros don't need to be exported. #132102

@Kriskras99

Description

@Kriskras99

Code

mod macros { #[macro_export] macro_rules! some_macro { () => {{println!("Hello, World")}}; } } pub use macros::*;

Current output

warning: unused import: `macros::*` --> src/lib.rs:8:9 | 8 | pub use macros::*; | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: `tester` (lib) generated 1 warning (run `cargo fix --lib -p tester` to apply 1 suggestion) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s 

Desired output

warning: unused import: `macros::*` --> src/lib.rs:8:9 | 8 | pub use macros::*; | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default = note: this import only imports macros exported with `#[macro_export]`, therefore the `pub use` does nothing warning: `tester` (lib) generated 1 warning (run `cargo fix --lib -p tester` to apply 1 suggestion) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s 

Rationale and extra context

I ran into this myself, because I'm so used to pub use ... functions/structs to nicely organise my libraries.
So I think this can also help others who don't realise that #[macro_export] makes the pub use unnecessary.

Other cases

No response

Rust Version

rustc 1.84.0-nightly (4f2f477 2024-10-23)
binary: rustc
commit-hash: 4f2f477
commit-date: 2024-10-23
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.L-unused_importsLint: unused_importsT-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