@@ -479,7 +479,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
479
479
) ;
480
480
481
481
if !need_migrations. is_empty ( ) {
482
- let migrations_text = migration_suggestion_for_2229 ( self . tcx , & need_migrations) ;
482
+ let ( migration_string, migrated_variables_concat) =
483
+ migration_suggestion_for_2229 ( self . tcx , & need_migrations) ;
483
484
484
485
let local_def_id = closure_def_id. expect_local ( ) ;
485
486
let closure_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( local_def_id) ;
@@ -495,15 +496,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
495
496
let ( sugg, app) =
496
497
match self . tcx . sess . source_map ( ) . span_to_snippet ( closure_body_span) {
497
498
Ok ( s) => (
498
- format ! ( "{{ {} {} }}" , migrations_text , s) ,
499
+ format ! ( "{{ {}; {} }}" , migration_string , s) ,
499
500
Applicability :: MachineApplicable ,
500
501
) ,
501
- Err ( _) => ( migrations_text . clone ( ) , Applicability :: HasPlaceholders ) ,
502
+ Err ( _) => ( migration_string . clone ( ) , Applicability :: HasPlaceholders ) ,
502
503
} ;
503
504
505
+ let diagnostic_msg = format ! (
506
+ "`{}` causes {} to be fully captured" ,
507
+ migration_string, migrated_variables_concat
508
+ ) ;
509
+
504
510
diagnostics_builder. span_suggestion (
505
511
closure_body_span,
506
- & format ! ( "You can restore original behavior adding `{}` to the closure/generator" , migrations_text ) ,
512
+ & diagnostic_msg ,
507
513
sugg,
508
514
app,
509
515
) ;
@@ -1537,16 +1543,29 @@ fn should_do_migration_analysis(tcx: TyCtxt<'_>, closure_id: hir::HirId) -> bool
1537
1543
!matches ! ( level, lint:: Level :: Allow )
1538
1544
}
1539
1545
1540
- fn migration_suggestion_for_2229 ( tcx : TyCtxt < ' _ > , need_migrations : & Vec < hir:: HirId > ) -> String {
1541
- let need_migrations_strings =
1542
- need_migrations. iter ( ) . map ( |v| format ! ( "&{}" , var_name( tcx, * v) ) ) . collect :: < Vec < _ > > ( ) ;
1543
- let migrations_list_concat = need_migrations_strings. join ( ", " ) ;
1546
+ /// Return a two string tuple (s1, s2)
1547
+ /// - s1: Line of code that is needed for the migration: eg: `let _ = (&x, ...)`.
1548
+ /// - s2: Comma separated names of the variables being migrated.
1549
+ fn migration_suggestion_for_2229 (
1550
+ tcx : TyCtxt < ' _ > ,
1551
+ need_migrations : & Vec < hir:: HirId > ,
1552
+ ) -> ( String , String ) {
1553
+ let need_migrations_variables =
1554
+ need_migrations. iter ( ) . map ( |v| var_name ( tcx, * v) ) . collect :: < Vec < _ > > ( ) ;
1555
+
1556
+ let migration_ref_concat =
1557
+ need_migrations_variables. iter ( ) . map ( |v| format ! ( "&{}" , v) ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ;
1544
1558
1545
- if 1 == need_migrations. len ( ) {
1546
- format ! ( "let _ = {}; " , migrations_list_concat )
1559
+ let migration_string = if 1 == need_migrations. len ( ) {
1560
+ format ! ( "let _ = {}" , migration_ref_concat )
1547
1561
} else {
1548
- format ! ( "let _ = ({});" , migrations_list_concat)
1549
- }
1562
+ format ! ( "let _ = ({})" , migration_ref_concat)
1563
+ } ;
1564
+
1565
+ let migrated_variables_concat =
1566
+ need_migrations_variables. iter ( ) . map ( |v| format ! ( "`{}`" , v) ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ;
1567
+
1568
+ ( migration_string, migrated_variables_concat)
1550
1569
}
1551
1570
1552
1571
/// Helper function to determine if we need to escalate CaptureKind from
0 commit comments