Skip to content

Conversation

rmartinho
Copy link

This will become an error in the future, and the defaults in impl are ignored anyway so it makes no sense to preserve them in the generated impl.

@kirillsemyonkin
Copy link
Collaborator

kirillsemyonkin commented Aug 21, 2025

ngl first time looking into this derive code, it is kinda weird. could just rewrite to

#[proc_macro_derive(ImplicitClone)]
pub fn derive_implicit_clone(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let mut input = syn::parse_macro_input!(item as syn::DeriveInput);
    input
        .generics
        .type_params_mut()
        .for_each(|type_param| type_param.bounds.push(syn::parse_quote! { ::implicit_clone::ImplicitClone }));

    let syn::DeriveInput {
        ident, generics, ..
    } = input;
    let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
    let res = quote! {
        impl #impl_generics ::implicit_clone::ImplicitClone for #ident #ty_generics #where_clause {}
    };
    res.into()
}

this way we just add bounds, and rest syn will figure out on its own

@rmartinho
Copy link
Author

I'm not super familiar with writing derive macros, so I tried to change as little as necessary.

I will try your implementation later and update the PR if there are no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants