@@ -139,40 +139,44 @@ fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<St
139
139
140
140
let mut example = String :: new ( ) ;
141
141
142
+ let use_path = build_path ( ast_func, ctx) ?;
142
143
let is_unsafe = ast_func. unsafe_token ( ) . is_some ( ) ;
143
144
let param_list = ast_func. param_list ( ) ?;
144
145
let ref_mut_params = ref_mut_params ( & param_list) ;
145
146
let self_name = self_name ( ast_func) ;
146
147
147
- format_to ! ( example, "use {};\n \n " , build_path ( ast_func , ctx ) ? ) ;
148
+ format_to ! ( example, "use {use_path };\n \n " ) ;
148
149
if let Some ( self_name) = & self_name {
149
- if let Some ( mtbl ) = is_ref_mut_self ( ast_func) {
150
- let mtbl = if mtbl == true { " mut" } else { "" } ;
151
- format_to ! ( example, "let{} { } = ;\n " , mtbl , self_name ) ;
150
+ if let Some ( mut_ ) = is_ref_mut_self ( ast_func) {
151
+ let mut_ = if mut_ == true { "mut " } else { "" } ;
152
+ format_to ! ( example, "let {mut_}{self_name } = ;\n " ) ;
152
153
}
153
154
}
154
155
for param_name in & ref_mut_params {
155
- format_to ! ( example, "let mut {} = ;\n " , param_name ) ;
156
+ format_to ! ( example, "let mut {param_name } = ;\n " ) ;
156
157
}
157
158
// Call the function, check result
158
159
let function_call = function_call ( ast_func, & param_list, self_name. as_deref ( ) , is_unsafe) ?;
159
160
if returns_a_value ( ast_func, ctx) {
160
161
if count_parameters ( & param_list) < 3 {
161
- format_to ! ( example, "assert_eq!({}, );\n " , function_call ) ;
162
+ format_to ! ( example, "assert_eq!({function_call }, );\n " ) ;
162
163
} else {
163
- format_to ! ( example, "let result = {};\n " , function_call ) ;
164
+ format_to ! ( example, "let result = {function_call };\n " ) ;
164
165
example. push_str ( "assert_eq!(result, );\n " ) ;
165
166
}
166
167
} else {
167
- format_to ! ( example, "{};\n " , function_call ) ;
168
+ format_to ! ( example, "{function_call };\n " ) ;
168
169
}
169
170
// Check the mutated values
170
- if is_ref_mut_self ( ast_func) == Some ( true ) {
171
- format_to ! ( example, "assert_eq!({}, );" , self_name?) ;
171
+ if let Some ( self_name) = & self_name {
172
+ if is_ref_mut_self ( ast_func) == Some ( true ) {
173
+ format_to ! ( example, "assert_eq!({self_name}, );" ) ;
174
+ }
172
175
}
173
176
for param_name in & ref_mut_params {
174
- format_to ! ( example, "assert_eq!({}, );" , param_name ) ;
177
+ format_to ! ( example, "assert_eq!({param_name }, );" ) ;
175
178
}
179
+
176
180
Some ( example)
177
181
}
178
182
@@ -189,7 +193,8 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
189
193
let intro_for_new = || {
190
194
let is_new = name == "new" ;
191
195
if is_new && ret_ty == self_ty {
192
- Some ( format ! ( "Creates a new [`{}`]." , linkable_self_ty?) )
196
+ let self_ty = linkable_self_ty?;
197
+ Some ( format ! ( "Creates a new [`{self_ty}`]." ) )
193
198
} else {
194
199
None
195
200
}
@@ -214,7 +219,9 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
214
219
} else {
215
220
""
216
221
} ;
217
- Some ( format ! ( "Returns{reference} the {what} of this [`{}`]." , linkable_self_ty?) )
222
+
223
+ let self_ty = linkable_self_ty?;
224
+ Some ( format ! ( "Returns{reference} the {what} of this [`{self_ty}`]." ) )
218
225
}
219
226
_ => None ,
220
227
} ;
@@ -228,7 +235,9 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
228
235
if what == "len" {
229
236
what = "length" . into ( )
230
237
} ;
231
- Some ( format ! ( "Sets the {what} of this [`{}`]." , linkable_self_ty?) )
238
+
239
+ let self_ty = linkable_self_ty?;
240
+ Some ( format ! ( "Sets the {what} of this [`{self_ty}`]." ) )
232
241
} ;
233
242
234
243
if let Some ( intro) = intro_for_new ( ) {
@@ -404,7 +413,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
404
413
// instance `TuplePat`) could be managed later.
405
414
Some ( ast:: Pat :: IdentPat ( ident_pat) ) => match ident_pat. name ( ) {
406
415
Some ( name) => match is_a_ref_mut_param ( & param) {
407
- true => format ! ( "&mut {}" , name ) ,
416
+ true => format ! ( "&mut {name}" ) ,
408
417
false => name. to_string ( ) ,
409
418
} ,
410
419
None => "_" . to_string ( ) ,
@@ -424,14 +433,15 @@ fn function_call(
424
433
let name = ast_func. name ( ) ?;
425
434
let arguments = arguments_from_params ( param_list) ;
426
435
let function_call = if param_list. self_param ( ) . is_some ( ) {
427
- format ! ( "{}.{}({})" , self_name?, name, arguments)
436
+ let self_ = self_name?;
437
+ format ! ( "{self_}.{name}({arguments})" )
428
438
} else if let Some ( implementation) = self_partial_type ( ast_func) {
429
- format ! ( "{}::{}({})" , implementation , name , arguments )
439
+ format ! ( "{implementation }::{name }({arguments })" )
430
440
} else {
431
- format ! ( "{}({})" , name , arguments )
441
+ format ! ( "{name }({arguments })" )
432
442
} ;
433
443
match is_unsafe {
434
- true => Some ( format ! ( "unsafe {{ {} }}" , function_call ) ) ,
444
+ true => Some ( format ! ( "unsafe {{ {function_call } }}" ) ) ,
435
445
false => Some ( function_call) ,
436
446
}
437
447
}
@@ -469,8 +479,8 @@ fn build_path(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
469
479
. unwrap_or_else ( || "*" . into ( ) ) ;
470
480
let module_def: ModuleDef = ctx. sema . to_def ( ast_func) ?. module ( ctx. db ( ) ) . into ( ) ;
471
481
match module_def. canonical_path ( ctx. db ( ) ) {
472
- Some ( path) => Some ( format ! ( "{}::{}::{}" , crate_name , path , leaf ) ) ,
473
- None => Some ( format ! ( "{}::{}" , crate_name , leaf ) ) ,
482
+ Some ( path) => Some ( format ! ( "{crate_name }::{path }::{leaf}" ) ) ,
483
+ None => Some ( format ! ( "{crate_name }::{leaf}" ) ) ,
474
484
}
475
485
}
476
486
0 commit comments