Skip to content

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

@kpreid

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

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