From 09bd42a15b4bd46bd12b7a222e44676ca0391f84 Mon Sep 17 00:00:00 2001 From: bsh98 Date: Sat, 6 Jan 2024 22:46:31 -0800 Subject: [PATCH] fix generics --- trait-variant/examples/variant.rs | 4 +++- trait-variant/src/variant.rs | 18 ++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/trait-variant/examples/variant.rs b/trait-variant/examples/variant.rs index 428e737..f175bb7 100644 --- a/trait-variant/examples/variant.rs +++ b/trait-variant/examples/variant.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::future::Future; +use std::{future::Future, ops::Add}; #[trait_variant::make(IntFactory: Send)] pub trait LocalIntFactory { @@ -36,6 +36,8 @@ where { const CONST: usize = 3; type F; + type A; + type B: Add; async fn take(&self, s: S); } diff --git a/trait-variant/src/variant.rs b/trait-variant/src/variant.rs index c2cb9c6..8e36a99 100644 --- a/trait-variant/src/variant.rs +++ b/trait-variant/src/variant.rs @@ -15,9 +15,9 @@ use syn::{ parse_macro_input, punctuated::Punctuated, token::{Comma, Plus}, - Error, FnArg, GenericParam, Generics, Ident, ItemTrait, Lifetime, Pat, PatType, Result, - ReturnType, Signature, Token, TraitBound, TraitItem, TraitItemConst, TraitItemFn, - TraitItemType, Type, TypeImplTrait, TypeParamBound, + Error, FnArg, GenericParam, Ident, ItemTrait, Lifetime, Pat, PatType, Result, ReturnType, + Signature, Token, TraitBound, TraitItem, TraitItemConst, TraitItemFn, TraitItemType, Type, + TypeImplTrait, TypeParamBound, }; struct Attrs { @@ -256,17 +256,11 @@ fn blanket_impl_item( } } TraitItem::Type(TraitItemType { - ident, - generics: - Generics { - params, - where_clause, - .. - }, - .. + ident, generics, .. }) => { + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { - type #ident<#params> = >::#ident<#params> #where_clause; + type #ident #impl_generics = >::#ident #ty_generics #where_clause; } } _ => Error::new_spanned(item, "unsupported item type").into_compile_error(),