diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -83,6 +83,15 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { Err(err) => return err.to_compile_error().into(), }; + for dyn_supertrait in &method_attrs.dynamized_supertraits { + if !trait_bounds(&original_trait.supertraits).any(|t| t.path.is_ident(dyn_supertrait)) { + return abort!( + dyn_supertrait.span(), + "this trait definition has no such supertrait" + ); + } + } + let mut type_converter = TypeConverter { collections: method_attrs.collections, assoc_type_conversions: HashMap::new(), @@ -185,11 +194,20 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { supertraits: original_trait .supertraits .iter() - .filter(|t| match t { - TypeParamBound::Trait(t) => !t.path.is_ident("Sized"), - TypeParamBound::Lifetime(_) => true, + .filter_map(|t| { + if let TypeParamBound::Trait(trait_bound) = t { + if let Some(ident) = trait_bound.path.get_ident() { + if ident == "Sized" { + return None; + } else if method_attrs.dynamized_supertraits.contains(ident) { + let mut bound = trait_bound.clone(); + bound.path.segments[0].ident = format_ident!("Dyn{}", ident); + return Some(TypeParamBound::Trait(bound)); + } + } + } + Some(t.clone()) }) - .cloned() .collect(), brace_token: Brace::default(), items: Vec::new(), |