Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Report errors on unsupported attributes #113

Merged
merged 1 commit into from
Jan 5, 2021
Merged

Conversation

TedDriggs
Copy link
Owner

darling pre-dates Rust support for non-meta attributes.
These increase flexibility for Rust code, but mean that not darling
does not parse all valid attributes.

darling previously ignored these outright, creating misleading errors.
This commit makes those explicit errors.

Fixes #96

@TedDriggs TedDriggs self-assigned this Jan 4, 2021
Copy link
Contributor

@jonasbb jonasbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates an error message like error: Unable to parse attribute: expected literal. This solves my problem with #96. Thanks for solving this issue.

@TedDriggs
Copy link
Owner Author

@jonasbb does the error put the span in the right place? The tests in this repo don't have a good way to show me where the span is referencing, which is unfortunate.

core/src/error/mod.rs Outdated Show resolved Hide resolved
core/src/error/mod.rs Outdated Show resolved Hide resolved
@jonasbb
Copy link
Contributor

jonasbb commented Jan 5, 2021

@TedDriggs Yes, the span looks right

error: Unable to parse attribute: expected literal
  --> $DIR/serde_as.rs:67:55
   |
67 |     #[serde_as(serialize_as = "123", deserialize_as = DisplayFromStr)]
   |                                                       ^^^^^^^^^^^^^^

@TedDriggs TedDriggs force-pushed the unsupported-attributes branch 2 times, most recently from 6a475d0 to cc978c0 Compare January 5, 2021 14:03
`darling` pre-dates Rust support for non-meta attributes.
These increase flexibility for Rust code, but mean that not `darling`
does not parse all valid attributes.

`darling` previously ignored these outright, creating misleading errors,
such as claiming all fields were missing. This commit makes unsupported
attributes explicit errors.

To allow for detailed diagnostic information in the future without
changing the crate's public API, the parsing of `Attribute` into
`MetaList` is handled in a new function that wraps `syn`'s own
`parse_meta`. This commit uses that structure to include an attribute
path in an example for the name-value error case; future commits could
expand that function to identify places where the caller may have
missed quotation marks, for example.

Fixes #96
@TedDriggs TedDriggs force-pushed the unsupported-attributes branch from cc978c0 to 8f4bb9c Compare January 5, 2021 14:27
@TedDriggs TedDriggs merged commit 9efe2f4 into master Jan 5, 2021
@TedDriggs TedDriggs deleted the unsupported-attributes branch January 5, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid attribute specifications being ignored; should cause compile error.
2 participants