11use proc_macro2:: { Span , TokenStream } ;
22use proc_macro_error:: emit_error;
3- use quote:: quote;
3+ use quote:: { quote, ToTokens } ;
44use syn:: parse:: { Parse , ParseStream } ;
55use syn:: visit_mut;
6- use syn:: { parse_file, Ident , ItemFn , LitStr , ReturnType , Signature } ;
6+ use syn:: { parse_file, GenericParam , Ident , ItemFn , LitStr , ReturnType , Signature } ;
77
88mod body;
99mod lifetime;
@@ -98,6 +98,19 @@ When used in function components and hooks, this hook is equivalent to:
9898 let output_type = & hook_sig. output_type ;
9999
100100 let ( impl_generics, ty_generics, where_clause) = generics. split_for_impl ( ) ;
101+ let call_generics = {
102+ let mut generics = generics. clone ( ) ;
103+
104+ // We need to filter out lifetimes.
105+ generics. params = generics
106+ . params
107+ . into_iter ( )
108+ . filter ( |m| !matches ! ( m, GenericParam :: Lifetime ( _) ) )
109+ . collect ( ) ;
110+
111+ let ( _impl_generics, ty_generics, _where_clause) = generics. split_for_impl ( ) ;
112+ ty_generics. as_turbofish ( ) . to_token_stream ( )
113+ } ;
101114
102115 let ctx_ident = Ident :: new ( "ctx" , Span :: mixed_site ( ) ) ;
103116
@@ -120,13 +133,13 @@ When used in function components and hooks, this hook is equivalent to:
120133 let hook_lifetime_plus = quote ! { #hook_lifetime + } ;
121134
122135 let boxed_inner_ident = Ident :: new ( "boxed_inner" , Span :: mixed_site ( ) ) ;
123- let boxed_fn_type = quote ! { :: std:: boxed:: Box <dyn #hook_lifetime_plus FnOnce ( & mut :: yew:: functional:: HookContext ) #inner_fn_rt> } ;
136+ let boxed_fn_type = quote ! { :: std:: boxed:: Box <dyn #hook_lifetime_plus :: std :: ops :: FnOnce ( & mut :: yew:: functional:: HookContext ) #inner_fn_rt> } ;
124137
125138 // We need boxing implementation for `impl Trait` arguments.
126139 quote ! {
127140 let #boxed_inner_ident = :: std:: boxed:: Box :: new(
128141 move |#ctx_ident: & mut :: yew:: functional:: HookContext | #inner_fn_rt {
129- #inner_fn_ident ( #ctx_ident, #( #input_args, ) * )
142+ #inner_fn_ident #call_generics ( #ctx_ident, #( #input_args, ) * )
130143 }
131144 ) as #boxed_fn_type;
132145
@@ -138,8 +151,6 @@ When used in function components and hooks, this hook is equivalent to:
138151 let args_ident = Ident :: new ( "args" , Span :: mixed_site ( ) ) ;
139152 let hook_struct_name = Ident :: new ( "HookProvider" , Span :: mixed_site ( ) ) ;
140153
141- let call_generics = ty_generics. as_turbofish ( ) ;
142-
143154 let phantom_types = hook_sig. phantom_types ( ) ;
144155 let phantom_lifetimes = hook_sig. phantom_lifetimes ( ) ;
145156
@@ -155,7 +166,7 @@ When used in function components and hooks, this hook is equivalent to:
155166 fn run( mut self , #ctx_ident: & mut :: yew:: functional:: HookContext ) -> Self :: Output {
156167 let ( #( #input_args, ) * ) = self . #args_ident;
157168
158- #inner_fn_ident( #ctx_ident, #( #input_args, ) * )
169+ #inner_fn_ident #call_generics ( #ctx_ident, #( #input_args, ) * )
159170 }
160171 }
161172
0 commit comments