Open
Description
Code
mod macros {
macro_rules! greet {
() => { println!("Hello, world!"); }
}
//pub(crate) use greet;
}
fn main() {
macros::greet!();
}
Current output
error[E0433]: failed to resolve: could not find `greet` in `module`
--> src/main.rs:10:13
|
10 | module::greet!();
| ^^^^^ could not find `greet` in `module`
warning: unused macro definition: `greet`
--> src/main.rs:2:18
|
2 | macro_rules! greet {
| ^^^^^
|
= note: `#[warn(unused_macros)]` on by default
Desired output
error[E0603]: macro `greet` is private
--> src/main.rs:10:13
|
10 | module::greet!();
| ^^^^^ private macro
|
note: the macro `greet` is defined here
--> src/main.rs:2:5
|
2 | macro_rules! greet {
| ^^^^^^^^^^^^^^^^^^
= help: consider adding `pub(crate) use greet;` to re-export the macro
(This could be an actual rustfix suggestion, though it should not have high certainty since they may not have intended to use a private macro.)
Rationale and extra context
We already give a better error for attempting to call a private function; this applies the same logic to private macros.
Rust Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Visibility / privacyDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Relevant to the compiler team, which will review and decide on the PR/issue.