-Z macro-backtrace doesn't provide new information
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
Any (I think) proc macro which outputs syntactically correct but semantically invalid code. I encountered this issue here when running cargo test easy.
Current output
This is the compiler error without -Z macro-backtrace:
error[E0282]: type annotations needed
--> pg-worm/src/query/table.rs:225:14
|
225 | #[derive(Model)]
| ^^^^^ cannot infer type
|
= note: this error originates in the derive macro `Model` (in Nightly builds, run with -Z macro-backtrace for more info)
And this is the ouput with the flag:
error[E0282]: type annotations needed
--> pg-worm/src/query/table.rs:225:14
|
225 | #[derive(Model)]
| ^^^^^
| |
| cannot infer type
| in this derive macro expansion
|
::: /home/me/code/pg-worm/pg-worm-derive/src/lib.rs:12:1
|
12 | pub fn derive(input: OldTokenStream) -> OldTokenStream {
| ------------------------------------------------------ in this expansion of `#[derive(Model)]`
Desired output
I would expect -Z macro-backtrace to show the error in the expanded code, so something like this (assuming this were the code produced):
error[E0282]: type annotations needed
--> pg-wprm/src/query/table.rs:255:14
225 | let foo = "bar".into();
| ^^^^
| |
| cannot infer type
| in this derive macro expansion
|
| ------------------------------------------------------ in this expansion of `#[derive(Model)]`
Rationale and extra context
As it stands, when code produced by a proc macro fails to compile for semantic reasons we only receive the error message, no span or note etc. Debugging such an error is no pleasant task and aften spending hours on separate days going through the cargo expand output I still can't figure out what is wrong with my code. I would expect the macro-backtrace flag to produce a more detailed account of what went wrong, including the span of the error in the expanded code.
Other cases
No response
Anything else?
No response
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 report with cargo test easy in the linked pg-worm project, comparing output with and without -Z macro-backtrace. Start from pg-worm-derive/src/lib.rs:12 and the derive use at pg-worm/src/query/table.rs:225, then trace the compiler's macro-backtrace handling. Done means semantic errors from proc-macro output include a useful span or location in the expanded code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100