Skip to content

Commit

Permalink
fix generics
Browse files Browse the repository at this point in the history
  • Loading branch information
bsh98 committed Jan 7, 2024
1 parent db73d60 commit 09bd42a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion trait-variant/examples/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -36,6 +36,8 @@ where
{
const CONST: usize = 3;
type F;
type A<const ANOTHER_CONST: u8>;
type B<T>: Add<T>;

async fn take(&self, s: S);
}
Expand Down
18 changes: 6 additions & 12 deletions trait-variant/src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> = <Self as #variant<#generic_names>>::#ident<#params> #where_clause;
type #ident #impl_generics = <Self as #variant<#generic_names>>::#ident #ty_generics #where_clause;
}
}
_ => Error::new_spanned(item, "unsupported item type").into_compile_error(),
Expand Down

0 comments on commit 09bd42a

Please sign in to comment.