Early exit on proc-macro invocation gives out unhelpful system error message
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
//! entry/src/main.rs
#[makro::makro(does not matter)]
#[derive(Debug)]
struct AlsoDoesNotMatter;
fn main() {
let doesnt = AlsoDoesNotMatter;
println!("{doesnt:#?}");
}
//! makro/src/lib.rs
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn makro(attr : TokenStream , _item : TokenStream) -> TokenStream {
println!("{attr}");
std::process::exit(0);
}
Current output
error: could not execute process `target/debug/entry` (never executed)
Caused by:
No such file or directory (os error 2)
Desired output
error: failed proc macro invocation
--> src/main.rs:9:15
|
9 | #[makro::makro(does not matter)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this macro failed to run
help: output from this macro
---START---
does not matter
--- END ---
help : this macro exited with the exit code : 0. if this macro is written in Rust, make sure that your proc macro function returns a `proc_macro::TokenStream` and refrain from using early exit measures such as `std::process::exit` and prefer healthier abrupt exit methods such as using `panic!()`
Rationale and extra context
None that I can think of
Other cases
This was found through iterating multiple times on another issue #160671, before running cargo clean the output was more like this:
Compiling entry v0.1.0 (/home/evopot/code/stringify/entry)
does not matter
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/entry`
Rust Version
evopot@DESKTOP-8NT487B ~/c/s/entry (master)> rustc --version --verbose
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 22.1.6
Anything else?
No :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure using entry/src/main.rs and makro/src/lib.rs, starting with the proc-macro attribute invocation and its process-exit behavior. Trace how the compiler handles the terminated proc-macro process and compare it with the requested diagnostic. Done means early exit produces a useful proc-macro error that includes the macro location and captured output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100