- Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
main.rs:
macro_rules! foo { () => { extern crate $crate; }; } foo!(); fn main() {}There's also an empty file at deps/lib$crate.rlib.
I run the command: rustc main.rs -L crate=deps. I get the following error:
error: expected identifier, found reserved identifier `$crate` --> main.rs:3:22 | 3 | extern crate $crate; | ^^^^^^ expected identifier, found reserved identifier ... 6 | foo!(); | ------ in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0786]: found invalid metadata files for crate `$crate` --> main.rs:3:9 | 3 | extern crate $crate; | ^^^^^^^^^^^^^^^^^^^^ ... 6 | foo!(); | ------ in this macro invocation | = note: failed to mmap file 'deps/lib$crate.rlib': memory map must have a non-zero length = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0786`. Since $crate is not a valid crate name, rustc probably should not be reading the lib$crate.rlib file at all. And based on the error message, rustc is actually even trying to parse that file.
See also #146967, which features a similar issue with use.
Meta
rustc --version --verbose:
rustc 1.91.1 (ed61e7d7e 2025-11-07) binary: rustc commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb commit-date: 2025-11-07 host: aarch64-apple-darwin release: 1.91.1 LLVM version: 21.1.2 Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: 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.Relevant to the compiler team, which will review and decide on the PR/issue.