rust-lang / rust-lang/rust

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

Open
#132,102 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints A-macros D-terse L-unused_imports T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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 (4f2f477fd 2024-10-23)
binary: rustc
commit-hash: 4f2f477fded0a47b21ed3f6aeddeafa5db8bf518
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning from the Rust code in src/lib.rs and compare the current and desired diagnostics. Start by tracing the unused_imports diagnostic for a pub use of a #[macro_export] macro, then add regression coverage for this case. Done means the warning includes the explanatory note shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.