Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reporting multiple errors from proc-macros #2892

Open
davidhewitt opened this issue Jan 19, 2023 · 0 comments
Open

Reporting multiple errors from proc-macros #2892

davidhewitt opened this issue Jan 19, 2023 · 0 comments

Comments

@davidhewitt
Copy link
Member

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 😄

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant