darling_core 0.24.0

Helper crate for proc-macro library for reading attributes into structs when implementing custom derives. Use https://crates.io/crates/darling in your code.
Documentation
use syn::spanned::Spanned;

/// Calls `FromMeta::<#ty>::from_none()` if the `#ty` implements `FromMeta`.
/// if it doesn't, evaluates to an `Option`.
pub fn from_none_call(ty: &syn::Type) -> proc_macro2::TokenStream {
    // If `ty` does not impl FromMeta, the compiler error should point
    // at the offending type rather than at the derive-macro call site.
    quote::quote_spanned!(ty.span() => {
        // Auto-ref specialization, described in detail in the doc
        // comments of the `autoref_specialization` module

        #[allow(unused)]
        use _darling::autoref_specialization::{
            // If `#ty` implements `FromMeta`, `SpecFromMeta::tag()` is used
            SpecFromMeta as _,
            // If it doesn't, `SpecFromMetaAll::tag()` is used
            SpecFromMetaAll as _
        };

        (&_darling::export::PhantomData::<#ty>).tag().from_none()
    })
}