@@ -273,85 +273,62 @@ fn check<'tcx>(
273
273
msg_span,
274
274
"unneeded late initialization" ,
275
275
|diag| {
276
- diag. tool_only_span_suggestion (
277
- local_stmt. span ,
278
- "remove the local" ,
279
- "" ,
280
- Applicability :: MachineApplicable ,
281
- ) ;
282
-
283
- diag. span_suggestion (
284
- assign. lhs_span ,
285
- format ! ( "declare `{binding_name}` here" ) ,
286
- let_snippet,
276
+ diag. multipart_suggestion (
277
+ format ! ( "move the declaration `{binding_name}` here" ) ,
278
+ vec ! [ ( local_stmt. span, String :: new( ) ) , ( assign. lhs_span, let_snippet) ] ,
287
279
Applicability :: MachineApplicable ,
288
280
) ;
289
281
} ,
290
282
) ;
291
283
} ,
292
284
ExprKind :: If ( cond, then_expr, Some ( else_expr) ) if !contains_let ( cond) => {
293
- let ( applicability, suggestions) = assignment_suggestions ( cx, binding_id, [ then_expr, else_expr] ) ?;
285
+ let ( applicability, mut suggestions) = assignment_suggestions ( cx, binding_id, [ then_expr, else_expr] ) ?;
294
286
295
287
span_lint_and_then (
296
288
cx,
297
289
NEEDLESS_LATE_INIT ,
298
290
local_stmt. span ,
299
291
"unneeded late initialization" ,
300
292
|diag| {
301
- diag. tool_only_span_suggestion ( local_stmt. span , "remove the local" , String :: new ( ) , applicability) ;
302
-
303
- diag. span_suggestion_verbose (
304
- usage. stmt . span . shrink_to_lo ( ) ,
305
- format ! ( "declare `{binding_name}` here" ) ,
306
- format ! ( "{let_snippet} = " ) ,
307
- applicability,
308
- ) ;
309
-
310
- diag. multipart_suggestion ( "remove the assignments from the branches" , suggestions, applicability) ;
293
+ suggestions. push ( ( local_stmt. span , String :: new ( ) ) ) ;
294
+ suggestions. push ( ( usage. stmt . span . shrink_to_lo ( ) , format ! ( "{let_snippet} = " ) ) ) ;
311
295
312
296
if usage. needs_semi {
313
- diag. span_suggestion (
314
- usage. stmt . span . shrink_to_hi ( ) ,
315
- "add a semicolon after the `if` expression" ,
316
- ";" ,
317
- applicability,
318
- ) ;
297
+ suggestions. push ( ( usage. stmt . span . shrink_to_hi ( ) , ";" . to_owned ( ) ) ) ;
319
298
}
299
+
300
+ diag. multipart_suggestion (
301
+ format ! (
302
+ "move the declaration `{binding_name}` here and remove the assignments from the branches"
303
+ ) ,
304
+ suggestions,
305
+ applicability,
306
+ ) ;
320
307
} ,
321
308
) ;
322
309
} ,
323
310
ExprKind :: Match ( _, arms, MatchSource :: Normal ) => {
324
- let ( applicability, suggestions) = assignment_suggestions ( cx, binding_id, arms. iter ( ) . map ( |arm| arm. body ) ) ?;
311
+ let ( applicability, mut suggestions) =
312
+ assignment_suggestions ( cx, binding_id, arms. iter ( ) . map ( |arm| arm. body ) ) ?;
325
313
326
314
span_lint_and_then (
327
315
cx,
328
316
NEEDLESS_LATE_INIT ,
329
317
local_stmt. span ,
330
318
"unneeded late initialization" ,
331
319
|diag| {
332
- diag. tool_only_span_suggestion ( local_stmt. span , "remove the local" , String :: new ( ) , applicability) ;
320
+ suggestions. push ( ( local_stmt. span , String :: new ( ) ) ) ;
321
+ suggestions. push ( ( usage. stmt . span . shrink_to_lo ( ) , format ! ( "{let_snippet} = " ) ) ) ;
333
322
334
- diag. span_suggestion_verbose (
335
- usage. stmt . span . shrink_to_lo ( ) ,
336
- format ! ( "declare `{binding_name}` here" ) ,
337
- format ! ( "{let_snippet} = " ) ,
338
- applicability,
339
- ) ;
323
+ if usage. needs_semi {
324
+ suggestions. push ( ( usage. stmt . span . shrink_to_hi ( ) , ";" . to_owned ( ) ) ) ;
325
+ }
340
326
341
327
diag. multipart_suggestion (
342
- " remove the assignments from the `match` arms",
328
+ format ! ( "move the declaration `{binding_name}` here and remove the assignments from the `match` arms") ,
343
329
suggestions,
344
330
applicability,
345
331
) ;
346
-
347
- if usage. needs_semi {
348
- diag. span_suggestion (
349
- usage. stmt . span . shrink_to_hi ( ) ,
350
- "add a semicolon after the `match` expression" ,
351
- ";" ,
352
- applicability,
353
- ) ;
354
- }
355
332
} ,
356
333
) ;
357
334
} ,
0 commit comments