@@ -479,7 +479,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
479479 ) ;
480480
481481 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) ;
483484
484485 let local_def_id = closure_def_id. expect_local ( ) ;
485486 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> {
495496 let ( sugg, app) =
496497 match self . tcx . sess . source_map ( ) . span_to_snippet ( closure_body_span) {
497498 Ok ( s) => (
498- format ! ( "{{ {} {} }}" , migrations_text , s) ,
499+ format ! ( "{{ {}; {} }}" , migration_string , s) ,
499500 Applicability :: MachineApplicable ,
500501 ) ,
501- Err ( _) => ( migrations_text . clone ( ) , Applicability :: HasPlaceholders ) ,
502+ Err ( _) => ( migration_string . clone ( ) , Applicability :: HasPlaceholders ) ,
502503 } ;
503504
505+ let diagnostic_msg = format ! (
506+ "`{}` causes {} to be fully captured" ,
507+ migration_string, migrated_variables_concat
508+ ) ;
509+
504510 diagnostics_builder. span_suggestion (
505511 closure_body_span,
506- & format ! ( "You can restore original behavior adding `{}` to the closure/generator" , migrations_text ) ,
512+ & diagnostic_msg ,
507513 sugg,
508514 app,
509515 ) ;
@@ -1537,16 +1543,29 @@ fn should_do_migration_analysis(tcx: TyCtxt<'_>, closure_id: hir::HirId) -> bool
15371543 !matches ! ( level, lint:: Level :: Allow )
15381544}
15391545
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 ( ", " ) ;
15441558
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 )
15471561 } 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)
15501569}
15511570
15521571/// Helper function to determine if we need to escalate CaptureKind from
0 commit comments