Skip to content

Teach pub(crate) use for E0364 on macro_rules! #145140

Closed

Description

@kpreid

Code

mod macros {
    macro_rules! foo { () => {}; }
    pub use foo;
}

Current output

error[E0364]: `foo` is only public within the crate, and cannot be re-exported outside
 --> src/lib.rs:3:13
  |
3 |     pub use foo;
  |             ^^^
  |
help: consider adding a `#[macro_export]` to the macro in the imported module
 --> src/lib.rs:2:5
  |
2 |     macro_rules! foo { () => {}; }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Desired output

In addition to the current output:

help: or, if you want to use the macro within this crate only, reduce the visibility to `pub(crate)`
   |
   | pub(crate) use foo;
   | ^^^^^^^^^^

Rationale and extra context

macro_rules! export behavior is unique and weirdly restricted, and needs to be taught in more detail so users can write the program that is as close to what they actually want as possible.

Rust Version

1.89.0

Anything else?

@rustbot label +A-macros

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 9, 2025
  2. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Aug 9, 2025
  3. makai410 commented on Aug 9, 2025

    @makai410
    Member

    @rustbot claim

  4. added 2 commits that reference this issue on Aug 18, 2025
    b58ab6a
    ec69df2
  5. added 2 commits that reference this issue on Aug 19, 2025
    bb1b595
    8568070
  6. added a commit that references this issue on Aug 19, 2025
    d150811
  7. added a commit that references this issue on Aug 20, 2025
    441cc2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-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