LukeMathWalker / LukeMathWalker/pavex
feat: Improve user-facing compiler errors when Pavex attribute macros return an error
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
Context
Attribute macros replace the item they were attached to. This is not the same behaviour you get with derive macros: in that case, the decorated item is left untouched, no matter what the macro expands to.
Issue
Let's consider a simple route definition:
#[pavex::get]
pub fn my_route() -> pavex::Response {
// [...]
}
#[pavex::get] will emit an error, since no path argument was provided.
Since it didn't expand successfully, no code will be emitted. As a consequence, there will be no definition for my_route in the crate that gets compiled by cargo.
Every single reference to my_route anywhere else in the codebase (e.g. in a unit test) will trigger an "undefined item" error from rustc.
Desired behaviour
Pavex attribute macros should always re-emit the item they were attached to in case of error, thus reducing noise for the end-user.
Otherwise, our own error gets lost in the flood of artificial issues that ended up causing by "swallowing" the item definition.
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
Start by locating Pavex's attribute macro implementations and the error paths used when required arguments are missing. Reproduce the route example and inspect the resulting compiler diagnostics, then verify that the attached item remains available and that the original macro error is still reported without the cascade of undefined-item errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100