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

Only include error locations when necessary #203

Merged
merged 1 commit into from Oct 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Derived impls of `FromMeta` will now error on literals, rather than silently ignoring them. [#193](https://github.com/TedDriggs/darling/pull/193)
- Don't include property paths in compile errors when spans are available.

## v0.14.1 (April 28, 2022)

Expand Down
11 changes: 10 additions & 1 deletion core/src/error/mod.rs
Expand Up @@ -446,7 +446,16 @@ impl From<syn::Error> for Error {
impl From<Error> for syn::Error {
fn from(e: Error) -> Self {
if e.len() == 1 {
syn::Error::new(e.span(), e)
if let Some(span) = e.explicit_span() {
// Don't include the location path if the error has an explicit span,
// since it will be redundant and isn't consistent with how rustc
// exposes errors.
syn::Error::new(span, e.kind)
} else {
// If the error's span is going to be the macro call site, include
// the location information to try and help the user pinpoint the issue.
syn::Error::new(e.span(), e)
}
} else {
let mut syn_errors = e.flatten().into_iter().map(syn::Error::from);
let mut error = syn_errors
Expand Down