Reporting multiple errors from proc-macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
At the moment our proc-macros are implemented such that they return on the first error they encounter.
I think in some cases it should be possible to collect multiple errors together so that all of these could be reported to the user. For example, the following code:
use pyo3::prelude::*;
#[pyclass]
struct Example {
#[pyo3(foo)]
x: i32,
#[pyo3(blah)]
y: i32,
}
will at time of writing report compilation errors like the following:
error: expected one of: `get`, `set`, `name`
--> src/lib.rs:5:12
|
5 | #[pyo3(foo)]
| ^^^
error: cannot find attribute `pyo3` in this scope
--> src/lib.rs:7:7
|
7 | #[pyo3(blah)]
| ^^^^
|
= note: `pyo3` is in scope, but it is a crate, not an attribute
This is because as soon as the error on "foo" occurs, the macro stops parsing and so the #[pyo3(blah)] attribute is never consumed.
A better pair of error messages could be the following:
error: expected one of: `get`, `set`, `name`
--> src/lib.rs:5:12
|
5 | #[pyo3(foo)]
| ^^^
error: expected one of: `get`, `set`, `name`
--> src/lib.rs:7:7
|
7 | #[pyo3(blah)]
| ^^^^
I think I'm unlikely to work on this any time soon myself, but it would be a nice UX improvement if anyone is interested in getting dirty with our proc-macros 😄
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 the proc-macro parsing entry point for the #[pyo3(...)] attributes and reproduce the example with invalid foo and blah arguments. Trace where parsing returns on the first error; done means both invalid attributes are consumed and reported with their respective diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100