-
Notifications
You must be signed in to change notification settings - Fork 68
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
Derived FromDeriveInput silently skips attributes that don't parse as syn::Meta #108
Comments
This is "by design" (ish). The lack of quotation marks around the value passed to #[darling(supports(struct_unit), attributes(table))]
pub struct InterpolatedDataTableArgs {
pub ident: Ident,
pub st: Path,
pub file: LitStr,
}
impl ::darling::FromDeriveInput for InterpolatedDataTableArgs {
fn from_derive_input(__di: &::syn::DeriveInput) -> ::darling::Result<Self> {
let mut __errors = ::darling::export::Vec::new();
let mut st: (bool, ::darling::export::Option<Path>) = (false, None);
let mut file: (bool, ::darling::export::Option<LitStr>) = (false, None);
use ::darling::ToTokens;
let mut __fwd_attrs: ::darling::export::Vec<::syn::Attribute> = ::alloc::vec::Vec::new();
for __attr in &__di.attrs {
match ::darling::export::ToString::to_string(&__attr.path.clone().into_token_stream())
.as_str()
{
"table" => {
if let ::darling::export::Ok(::syn::Meta::List(ref __data)) =
__attr.parse_meta()
{
let __items = &__data.nested;
for __item in __items {
if let ::syn::NestedMeta::Meta(ref __inner) = *__item {
let __name = __inner
.path()
.segments
.iter()
.map(|s| s.ident.to_string())
.collect::<Vec<String>>()
.join("::");
match __name.as_str() {
"st" => {
if !st.0 {
match ::darling::FromMeta::from_meta(__inner)
.map_err(|e| e.with_span(&__inner).at("st"))
{
::darling::export::Ok(__val) => {
st = (true, ::darling::export::Some(__val));
}
::darling::export::Err(__err) => {
st = (true, None);
__errors.push(__err);
}
}
} else {
__errors.push(
::darling::Error::duplicate_field("st")
.with_span(&__inner),
);
}
}
"file" => {
if !file.0 {
match ::darling::FromMeta::from_meta(__inner)
.map_err(|e| e.with_span(&__inner).at("file"))
{
::darling::export::Ok(__val) => {
file = (true, ::darling::export::Some(__val));
}
::darling::export::Err(__err) => {
file = (true, None);
__errors.push(__err);
}
}
} else {
__errors.push(
::darling::Error::duplicate_field("file")
.with_span(&__inner),
);
}
}
__other => {
__errors.push(
::darling::Error::unknown_field_with_alts(
__other,
&["st", "file"],
)
.with_span(__inner),
);
}
}
}
}
} else {
continue;
}
}
_ => continue,
}
}
#[allow(unused_variables)]
fn __validate_body(__body: &::syn::Data) -> ::darling::Result<()> {
match *__body {
::syn::Data::Enum(ref data) => {
fn validate_variant(data: &::syn::Fields) -> ::darling::Result<()> {
::darling::export::Err(::darling::Error::unsupported_shape("enum"))
}
for variant in &data.variants {
validate_variant(&variant.fields)?;
}
Ok(())
}
::syn::Data::Struct(ref struct_data) => {
let data = &struct_data.fields;
match *data {
::syn::Fields::Unit => ::darling::export::Ok(()),
::syn::Fields::Unnamed(ref fields) if fields.unnamed.len() == 1 => {
::darling::export::Err(::darling::Error::unsupported_shape("newtype"))
}
::syn::Fields::Unnamed(_) => {
::darling::export::Err(::darling::Error::unsupported_shape("tuple"))
}
::syn::Fields::Named(_) => {
::darling::export::Err(::darling::Error::unsupported_shape("named"))
}
}
}
::syn::Data::Union(_) => {
::std::rt::begin_panic("internal error: entered unreachable code")
}
}
}
__validate_body(&__di.data)?;
if !st.0 {
__errors.push(::darling::Error::missing_field("st"));
}
if !file.0 {
__errors.push(::darling::Error::missing_field("file"));
}
if !__errors.is_empty() {
return ::darling::export::Err(::darling::Error::multiple(__errors));
}
::darling::export::Ok(InterpolatedDataTableArgs {
ident: __di.ident.clone(),
st: st
.1
.expect("Uninitialized fields without defaults were already checked"),
file: file
.1
.expect("Uninitialized fields without defaults were already checked"),
})
}
} The current behavior appears to be the result of the history of converting It's possible for I'm supportive of making that change, but 1) it'll require a minor version bump because it could break existing library users and 2) it may require an escape hatch, which I'll need to think about a bit. In the meantime, adding the quotation marks will unblock you. |
This is actually a duplicate of #96; let's move the discussion there. |
When attempting to get this struct
from this derive:
I get these errors that both
st
andfile
are not missing, yet they can be seen right above, and in the following clip of the DeriveInputDeriveInput
The text was updated successfully, but these errors were encountered: