diff --git a/packages/yew-macro/src/hook/mod.rs b/packages/yew-macro/src/hook/mod.rs index f22fd4f722e..a60ecbd551d 100644 --- a/packages/yew-macro/src/hook/mod.rs +++ b/packages/yew-macro/src/hook/mod.rs @@ -144,11 +144,13 @@ pub fn hook_impl(hook: HookFn) -> syn::Result { let as_boxed_fn = with_output.then(|| quote! { as #boxed_fn_type }); + let generic_types = generics.type_params().map(|t| &t.ident); + // We need boxing implementation for `impl Trait` arguments. quote! { let #boxed_inner_ident = ::std::boxed::Box::new( move |#ctx_ident: &mut ::yew::functional::HookContext| #inner_fn_rt { - #inner_fn_ident (#ctx_ident, #(#input_args,)*) + #inner_fn_ident :: <#(#generic_types,)*> (#ctx_ident, #(#input_args,)*) } ) #as_boxed_fn; diff --git a/packages/yew-macro/tests/hook_attr/hook-trait-item-pass.rs b/packages/yew-macro/tests/hook_attr/hook-trait-item-pass.rs new file mode 100644 index 00000000000..7fc8ae6dcc8 --- /dev/null +++ b/packages/yew-macro/tests/hook_attr/hook-trait-item-pass.rs @@ -0,0 +1,22 @@ +use std::marker::PhantomData; + +pub struct QueryState { + p: PhantomData +} + +pub trait MyTrait { + type Associated; +} + + +#[yew::hook] +pub fn use_query_state( + selector: impl yew::html::IntoPropValue, +) -> QueryState +where + Props: MyTrait, +{ + QueryState:: { p: PhantomData:: } +} + +fn main() {} \ No newline at end of file