Skip to content

Commit

Permalink
Only include error locations when necessary
Browse files Browse the repository at this point in the history
When spans are available, locations in the message add noise.
  • Loading branch information
TedDriggs committed Oct 26, 2022
1 parent f77e999 commit 6ba9735
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit 6ba9735

Please sign in to comment.