Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TedDriggs/darling
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.14.1
Choose a base ref
...
head repository: TedDriggs/darling
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.14.2
Choose a head ref
  • 9 commits
  • 9 files changed
  • 3 contributors

Commits on Jul 5, 2022

  1. Fix clippy violation

    TedDriggs committed Jul 5, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b71b23e View commit details

Commits on Aug 24, 2022

  1. Copy the full SHA
    fad4cb7 View commit details

Commits on Sep 8, 2022

  1. Emit Error when parsing FromMeta containing NestedMeta::Lit (#193)

    darling silently ignored literals in NestedMeta, which could indirectly cause confusing error messages if the user provided something that wasn't of the intended format.
    
    This update makes that error more explicit, and includes tests to showcase the behavior.
    
    Fixes #192
    leighmcculloch authored Sep 8, 2022
    Copy the full SHA
    161587a View commit details
  2. Add #193 to changelog

    TedDriggs committed Sep 8, 2022
    Copy the full SHA
    9e4ad34 View commit details
  3. Copy the full SHA
    2dd15cd View commit details

Commits on Sep 26, 2022

  1. Fix clippy violation

    TedDriggs committed Sep 26, 2022
    Copy the full SHA
    ab279f5 View commit details
  2. Update docs

    - Accurately label the type of fields in FromVariant derivers
    - Add bounds constraint to magic field docs
    
    Fix #200
    TedDriggs committed Sep 26, 2022
    Copy the full SHA
    f77e999 View commit details

Commits on Oct 26, 2022

  1. Only include error locations when necessary

    When spans are available, locations in the message add noise.
    TedDriggs committed Oct 26, 2022
    Copy the full SHA
    6ba9735 View commit details
  2. Bump version to 0.14.2

    TedDriggs committed Oct 26, 2022
    Copy the full SHA
    2186347 View commit details
Showing with 109 additions and 19 deletions.
  1. +5 −0 CHANGELOG.md
  2. +4 −4 Cargo.toml
  3. +1 −1 core/Cargo.toml
  4. +11 −5 core/src/codegen/variant_data.rs
  5. +18 −5 core/src/error/mod.rs
  6. +1 −1 core/src/from_meta.rs
  7. +2 −2 macro/Cargo.toml
  8. +1 −1 src/lib.rs
  9. +66 −0 tests/from_meta.rs
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.14.2 (October 26, 2022)

- 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. [#203](https://github.com/TedDriggs/darling/pull/203)

## v0.14.1 (April 28, 2022)

- Fix a bug where using a trait that accepts `#[darling(attributes(...))]` without specifying any attributes would emit code that did not compile. [#183](https://github.com/TedDriggs/darling/issues/183)
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "darling"
version = "0.14.1"
version = "0.14.2"
authors = ["Ted Driggs <ted.driggs@outlook.com>"]
repository = "https://github.com/TedDriggs/darling"
documentation = "https://docs.rs/darling/0.14.1"
documentation = "https://docs.rs/darling/0.14.2"
description = """
A proc-macro library for reading attributes into structs when
implementing custom derives.
@@ -17,8 +17,8 @@ exclude = ["/.travis.yml", "/publish.sh", "/.github/**"]
maintenance = { status = "actively-developed" }

[dependencies]
darling_core = { version = "=0.14.1", path = "core" }
darling_macro = { version = "=0.14.1", path = "macro" }
darling_core = { version = "=0.14.2", path = "core" }
darling_macro = { version = "=0.14.2", path = "macro" }

[dev-dependencies]
proc-macro2 = "1.0.37"
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "darling_core"
version = "0.14.1"
version = "0.14.2"
authors = ["Ted Driggs <ted.driggs@outlook.com>"]
repository = "https://github.com/TedDriggs/darling"
description = """
16 changes: 11 additions & 5 deletions core/src/codegen/variant_data.rs
Original file line number Diff line number Diff line change
@@ -58,11 +58,17 @@ impl<'a> FieldsGen<'a> {

quote!(
for __item in __items {
if let ::syn::NestedMeta::Meta(ref __inner) = *__item {
let __name = ::darling::util::path_to_string(__inner.path());
match __name.as_str() {
#(#arms)*
__other => { #handle_unknown }
match *__item {
::syn::NestedMeta::Meta(ref __inner) => {
let __name = ::darling::util::path_to_string(__inner.path());
match __name.as_str() {
#(#arms)*
__other => { #handle_unknown }
}
}
::syn::NestedMeta::Lit(ref __inner) => {
__errors.push(::darling::Error::unsupported_format("literal")
.with_span(__inner));
}
}
}
23 changes: 18 additions & 5 deletions core/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -683,10 +692,14 @@ impl Extend<Error> for Accumulator {

impl Drop for Accumulator {
fn drop(&mut self) {
if let Some(errors) = &mut self.0 {
match errors.len() {
0 => panic!("darling::error::Accumulator dropped without being finished"),
error_count => panic!("darling::error::Accumulator dropped without being finished. {} errors were lost.", error_count)
// don't try to panic if we are currently unwinding a panic
// otherwise we end up with an unhelful "thread panicked while panicking. aborting." message
if !std::thread::panicking() {
if let Some(errors) = &mut self.0 {
match errors.len() {
0 => panic!("darling::error::Accumulator dropped without being finished"),
error_count => panic!("darling::error::Accumulator dropped without being finished. {} errors were lost.", error_count)
}
}
}
}
2 changes: 1 addition & 1 deletion core/src/from_meta.rs
Original file line number Diff line number Diff line change
@@ -621,7 +621,7 @@ mod tests {

#[test]
fn unit_succeeds() {
let () = fm::<()>(quote!(ignore));
fm::<()>(quote!(ignore));
}

#[test]
4 changes: 2 additions & 2 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "darling_macro"
version = "0.14.1"
version = "0.14.2"
authors = ["Ted Driggs <ted.driggs@outlook.com>"]
repository = "https://github.com/TedDriggs/darling"
description = """
@@ -13,7 +13,7 @@ edition = "2018"
[dependencies]
quote = "1.0.18"
syn = "1.0.91"
darling_core = { version = "=0.14.1", path = "../core" }
darling_core = { version = "=0.14.2", path = "../core" }

[lib]
proc-macro = true
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@
//! |---|---|---|
//! |`ident`|`syn::Ident`|The identifier of the passed-in variant|
//! |`discriminant`|`Option<syn::Expr>`|For a variant such as `Example = 2`, the `2`|
//! |`fields`|`Option<darling::ast::Fields<__>>`|The fields associated with the variant|
//! |`fields`|`darling::ast::Fields<T> where T: FromField`|The fields associated with the variant|
//! |`attrs`|`Vec<syn::Attribute>`|The forwarded attributes from the passed in variant. These are controlled using the `forward_attrs` attribute.|
extern crate core;
66 changes: 66 additions & 0 deletions tests/from_meta.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use darling::{Error, FromMeta};
use syn::parse_quote;

#[derive(Debug, FromMeta)]
struct Meta {
#[darling(default)]
meta1: Option<String>,
#[darling(default)]
meta2: bool,
}

#[test]
fn nested_meta_meta_value() {
let meta = Meta::from_list(&[parse_quote! {
meta1 = "thefeature"
}])
.unwrap();
assert_eq!(meta.meta1, Some("thefeature".to_string()));
assert!(!meta.meta2);
}

#[test]
fn nested_meta_meta_bool() {
let meta = Meta::from_list(&[parse_quote! {
meta2
}])
.unwrap();
assert_eq!(meta.meta1, None);
assert!(meta.meta2);
}

#[test]
fn nested_meta_lit_string_errors() {
let err = Meta::from_list(&[parse_quote! {
"meta2"
}])
.unwrap_err();
assert_eq!(
err.to_string(),
Error::unsupported_format("literal").to_string()
);
}

#[test]
fn nested_meta_lit_integer_errors() {
let err = Meta::from_list(&[parse_quote! {
2
}])
.unwrap_err();
assert_eq!(
err.to_string(),
Error::unsupported_format("literal").to_string()
);
}

#[test]
fn nested_meta_lit_bool_errors() {
let err = Meta::from_list(&[parse_quote! {
true
}])
.unwrap_err();
assert_eq!(
err.to_string(),
Error::unsupported_format("literal").to_string()
);
}