Skip to content

Commit 09bd42a

Browse files
committed
fix generics
1 parent db73d60 commit 09bd42a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

trait-variant/examples/variant.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use std::future::Future;
9+
use std::{future::Future, ops::Add};
1010

1111
#[trait_variant::make(IntFactory: Send)]
1212
pub trait LocalIntFactory {
@@ -36,6 +36,8 @@ where
3636
{
3737
const CONST: usize = 3;
3838
type F;
39+
type A<const ANOTHER_CONST: u8>;
40+
type B<T>: Add<T>;
3941

4042
async fn take(&self, s: S);
4143
}

trait-variant/src/variant.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use syn::{
1515
parse_macro_input,
1616
punctuated::Punctuated,
1717
token::{Comma, Plus},
18-
Error, FnArg, GenericParam, Generics, Ident, ItemTrait, Lifetime, Pat, PatType, Result,
19-
ReturnType, Signature, Token, TraitBound, TraitItem, TraitItemConst, TraitItemFn,
20-
TraitItemType, Type, TypeImplTrait, TypeParamBound,
18+
Error, FnArg, GenericParam, Ident, ItemTrait, Lifetime, Pat, PatType, Result, ReturnType,
19+
Signature, Token, TraitBound, TraitItem, TraitItemConst, TraitItemFn, TraitItemType, Type,
20+
TypeImplTrait, TypeParamBound,
2121
};
2222

2323
struct Attrs {
@@ -256,17 +256,11 @@ fn blanket_impl_item(
256256
}
257257
}
258258
TraitItem::Type(TraitItemType {
259-
ident,
260-
generics:
261-
Generics {
262-
params,
263-
where_clause,
264-
..
265-
},
266-
..
259+
ident, generics, ..
267260
}) => {
261+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
268262
quote! {
269-
type #ident<#params> = <Self as #variant<#generic_names>>::#ident<#params> #where_clause;
263+
type #ident #impl_generics = <Self as #variant<#generic_names>>::#ident #ty_generics #where_clause;
270264
}
271265
}
272266
_ => Error::new_spanned(item, "unsupported item type").into_compile_error(),

0 commit comments

Comments
 (0)