Closed andrewbaxter closed 2 months ago
The following produces an error as expected:
use darling::{ FromDeriveInput, }; use syn::{ parse_quote, }; #[derive(Default, FromDeriveInput)] #[darling(attributes(demo))] pub struct Receiver { example1: Option<String>, } fn main() { Receiver::from_derive_input(&parse_quote!{ #[demo(example2 = "hi")] struct Example; }).unwrap(); }
called `Result::unwrap()` on an `Err` value: Error { kind: UnknownField(ErrorUnknownField { name: "example2", did_you_mean: Some((0.95, "example1")) }), locations: [], span: Some(Span) }
However this runs with no error:
use darling::{ FromField, }; use syn::{ parse_quote, ItemStruct, }; #[derive(Default, FromField)] pub struct Receiver { example1: Option<String>, } fn main() { let s: ItemStruct = parse_quote!{ struct Example { #[demo(example2 = "hi")] x: u32, } }; Receiver::from_field(&s.fields.into_iter().next().unwrap()).unwrap(); }
This happens both on the latest commit c330c3440bfecf3d556ffa1f03c96c7b7eac416b and in the latest release.
c330c3440bfecf3d556ffa1f03c96c7b7eac416b
Edit: default is unnecessary, happens when non-default too.
default
Ack, sorry. I thought attributes(x) was only for from_derive_input, but it's required if you want an enclosing attribute anywhere.
attributes(x)
from_derive_input
The following produces an error as expected:
However this runs with no error:
This happens both on the latest commit
c330c3440bfecf3d556ffa1f03c96c7b7eac416b
and in the latest release.Edit:
default
is unnecessary, happens when non-default too.