From 94c23e4303dd7721e42e275226667e36448b9b92 Mon Sep 17 00:00:00 2001 From: b05902132 Date: Tue, 23 Nov 2021 21:53:26 +0800 Subject: [PATCH] Support default SlotFragment implmentations --- pyo3-macros-backend/src/pyimpl.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyo3-macros-backend/src/pyimpl.rs b/pyo3-macros-backend/src/pyimpl.rs index fec4836d929..ec74693b2b9 100644 --- a/pyo3-macros-backend/src/pyimpl.rs +++ b/pyo3-macros-backend/src/pyimpl.rs @@ -150,6 +150,9 @@ pub fn gen_default_slot_impls(cls: &syn::Ident, method_defs: Vec) - .collect(); let mut proto_impls = Vec::new(); + let mut trait_impls = Vec::new(); + + let mut implemented_proto_fragments = HashSet::new(); for meth in &mut method_defs { let options = PyFunctionOptions::from_attrs(&mut meth.attrs).unwrap(); @@ -158,8 +161,10 @@ pub fn gen_default_slot_impls(cls: &syn::Ident, method_defs: Vec) - let attrs = get_cfg_attributes(&meth.attrs); proto_impls.push(quote!(#(#attrs)* #token_stream)) } - GeneratedPyMethod::SlotTraitImpl(..) => { - todo!() + GeneratedPyMethod::SlotTraitImpl(method_name, token_stream) => { + implemented_proto_fragments.insert(method_name); + let attrs = get_cfg_attributes(&meth.attrs); + trait_impls.push(quote!(#(#attrs)* #token_stream)); } GeneratedPyMethod::Method(_) | GeneratedPyMethod::TraitImpl(_) => { panic!("Only protocol methods can have default implementation!") @@ -167,6 +172,8 @@ pub fn gen_default_slot_impls(cls: &syn::Ident, method_defs: Vec) - } } + add_shared_proto_slots(&ty, &mut proto_impls, implemented_proto_fragments); + quote! { impl #cls { #(#method_defs)*