@@ -107,31 +107,48 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
107107 |edit| {
108108 // Create the function
109109 let method_source = match ctx. sema . source ( method) {
110- Some ( source) => source. value ,
110+ Some ( source) => {
111+ let v = source. value . clone_for_update ( ) ;
112+ let source_scope = ctx. sema . scope ( v. syntax ( ) ) ;
113+ let target_scope = ctx. sema . scope ( strukt. syntax ( ) ) ;
114+ if let ( Some ( s) , Some ( t) ) = ( source_scope, target_scope) {
115+ PathTransform :: generic_transformation ( & t, & s) . apply ( v. syntax ( ) ) ;
116+ }
117+ v
118+ }
111119 None => return ,
112120 } ;
121+
113122 let vis = method_source. visibility ( ) ;
123+ let is_async = method_source. async_token ( ) . is_some ( ) ;
124+ let is_const = method_source. const_token ( ) . is_some ( ) ;
125+ let is_unsafe = method_source. unsafe_token ( ) . is_some ( ) ;
126+
114127 let fn_name = make:: name ( & name) ;
128+
129+ let type_params = method_source. generic_param_list ( ) ;
130+ let where_clause = method_source. where_clause ( ) ;
115131 let params =
116132 method_source. param_list ( ) . unwrap_or_else ( || make:: param_list ( None , [ ] ) ) ;
117- let type_params = method_source. generic_param_list ( ) ;
118- let arg_list = match method_source. param_list ( ) {
119- Some ( list) => convert_param_list_to_arg_list ( list) ,
120- None => make:: arg_list ( [ ] ) ,
121- } ;
133+
134+ // compute the `body`
135+ let arg_list = method_source
136+ . param_list ( )
137+ . map ( |list| convert_param_list_to_arg_list ( list) )
138+ . unwrap_or_else ( || make:: arg_list ( [ ] ) ) ;
139+
122140 let tail_expr = make:: expr_method_call ( field, make:: name_ref ( & name) , arg_list) ;
123- let ret_type = method_source. ret_type ( ) ;
124- let is_async = method_source. async_token ( ) . is_some ( ) ;
125- let is_const = method_source. const_token ( ) . is_some ( ) ;
126- let is_unsafe = method_source. unsafe_token ( ) . is_some ( ) ;
127141 let tail_expr_finished =
128142 if is_async { make:: expr_await ( tail_expr) } else { tail_expr } ;
129143 let body = make:: block_expr ( [ ] , Some ( tail_expr_finished) ) ;
144+
145+ let ret_type = method_source. ret_type ( ) ;
146+
130147 let f = make:: fn_ (
131148 vis,
132149 fn_name,
133150 type_params,
134- method_source . where_clause ( ) ,
151+ where_clause,
135152 params,
136153 body,
137154 ret_type,
@@ -184,12 +201,6 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
184201 let assoc_items = impl_def. get_or_create_assoc_item_list ( ) ;
185202 assoc_items. add_item ( f. clone ( ) . into ( ) ) ;
186203
187- if let Some ( ( target, source) ) =
188- ctx. sema . scope ( strukt. syntax ( ) ) . zip ( ctx. sema . scope ( method_source. syntax ( ) ) )
189- {
190- PathTransform :: generic_transformation ( & target, & source) . apply ( f. syntax ( ) ) ;
191- }
192-
193204 if let Some ( cap) = ctx. config . snippet_cap {
194205 edit. add_tabstop_before ( cap, f)
195206 }
0 commit comments