diff options
-rw-r--r-- | src/lib.rs | 20 | ||||
-rw-r--r-- | tests/tests.rs | 4 |
2 files changed, 15 insertions, 9 deletions
@@ -84,7 +84,9 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { }; for dyn_supertrait in &method_attrs.dynamized_supertraits { - if !trait_bounds(&original_trait.supertraits).any(|t| t.path.is_ident(dyn_supertrait)) { + if !trait_bounds(&original_trait.supertraits) + .any(|t| t.path.segments[0].ident == *dyn_supertrait) + { return abort!( dyn_supertrait.span(), "this trait definition has no such supertrait" @@ -206,14 +208,14 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { .iter() .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)); - } + if trait_bound.path.is_ident("Sized") { + return None; + } + let ident = &trait_bound.path.segments[0].ident; + 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()) diff --git a/tests/tests.rs b/tests/tests.rs index 11bf10d..aa5e996 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -298,6 +298,10 @@ trait OneTrait: SomeTrait { fn test(&self) -> Self::X; } +#[dynamize::dynamize] +#[dynamized(Foo)] +trait OtherTrait<X>: Foo<X> {} + struct SuperError; trait Cache {} #[dynamize::dynamize] |