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

impl From<syn::Error> for Error #116

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Any crates using `darling` that relied on those attributes being silently ignored could see new errors reported in their dependent crates. [#113](https://github.com/TedDriggs/darling/pull/113)
- Impl `syn::spanned::Spanned` for `darling::util::SpannedValue` [#113](https://github.com/TedDriggs/darling/pull/113)
- Add `darling::util::parse_attribute_to_meta_list` to provide useful errors during attribute parsing [#113](https://github.com/TedDriggs/darling/pull/113)
- Add `impl From<syn::Error> for Error` to losslessly propagate `syn` errors [#116](https://github.com/TedDriggs/darling/pull/116)

## v0.11.0 (December 14, 2020)
- Bump minor version due to unexpected breaking change [#107](https://github.com/TedDriggs/darling/issues/107)
Expand Down
13 changes: 13 additions & 0 deletions core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,19 @@ impl fmt::Display for Error {
}
}

impl From<syn::Error> for Error {
fn from(e: syn::Error) -> Self {
// This impl assumes there is nothing but the message and span that needs to be preserved
// from the passed-in error. If this changes at some point, a new ErrorKind should be made
// to hold the syn::Error, and this impl should preserve it unmodified while setting its own
// span to be a copy of the passed-in error.
Self {
span: Some(e.span()),
..Self::custom(e)
}
}
}

// Don't want to publicly commit to Error supporting equality yet, but
// not having it makes testing very difficult. Note that spans are not
// considered for equality since that would break testing in most cases.
Expand Down