@@ -86,7 +86,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
86
86
/// Intermediate format to store the hir_id pointing to the use that resulted in the
87
87
/// corresponding place being captured and a String which contains the captured value's
88
88
/// name (i.e: a.b.c)
89
- type CapturesInfo = ( Option < hir:: HirId > , String ) ;
89
+ #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
90
+ enum CapturesInfo {
91
+ CapturingLess { source_expr : Option < hir:: HirId > , var_name : String } ,
92
+ }
90
93
91
94
/// Intermediate format to store information needed to generate migration lint. The tuple
92
95
/// contains the hir_id pointing to the use that resulted in the
@@ -963,7 +966,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
963
966
964
967
if !capture_problems. is_empty ( ) {
965
968
problematic_captures. insert (
966
- ( capture. info . path_expr_id , capture. to_string ( self . tcx ) ) ,
969
+ CapturesInfo :: CapturingLess {
970
+ source_expr : capture. info . path_expr_id ,
971
+ var_name : capture. to_string ( self . tcx ) ,
972
+ } ,
967
973
capture_problems,
968
974
) ;
969
975
}
@@ -986,6 +992,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
986
992
///
987
993
/// This function only returns a HashSet of CapturesInfo for significant drops. If there
988
994
/// are no significant drops than None is returned
995
+ #[ instrument( level = "debug" , skip( self ) ) ]
989
996
fn compute_2229_migrations_for_drop (
990
997
& self ,
991
998
closure_def_id : DefId ,
@@ -997,12 +1004,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
997
1004
let ty = self . infcx . resolve_vars_if_possible ( self . node_ty ( var_hir_id) ) ;
998
1005
999
1006
if !ty. has_significant_drop ( self . tcx , self . tcx . param_env ( closure_def_id. expect_local ( ) ) ) {
1007
+ debug ! ( "does not have significant drop" ) ;
1000
1008
return None ;
1001
1009
}
1002
1010
1003
1011
let Some ( root_var_min_capture_list) = min_captures. and_then ( |m| m. get ( & var_hir_id) ) else {
1004
1012
// The upvar is mentioned within the closure but no path starting from it is
1005
- // used.
1013
+ // used. This occurs when you have (e.g.)
1014
+ //
1015
+ // ```
1016
+ // let x = move || {
1017
+ // let _ = y;
1018
+ // });
1019
+ // ```
1020
+ debug ! ( "no path starting from it is used" ) ;
1021
+
1006
1022
1007
1023
match closure_clause {
1008
1024
// Only migrate if closure is a move closure
@@ -1012,6 +1028,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1012
1028
1013
1029
return None ;
1014
1030
} ;
1031
+ debug ! ( ?root_var_min_capture_list) ;
1015
1032
1016
1033
let mut projections_list = Vec :: new ( ) ;
1017
1034
let mut diagnostics_info = FxHashSet :: default ( ) ;
@@ -1021,19 +1038,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1021
1038
// Only care about captures that are moved into the closure
1022
1039
ty:: UpvarCapture :: ByValue ( ..) => {
1023
1040
projections_list. push ( captured_place. place . projections . as_slice ( ) ) ;
1024
- diagnostics_info. insert ( (
1025
- captured_place. info . path_expr_id ,
1026
- captured_place. to_string ( self . tcx ) ,
1027
- ) ) ;
1041
+ diagnostics_info. insert ( CapturesInfo :: CapturingLess {
1042
+ source_expr : captured_place. info . path_expr_id ,
1043
+ var_name : captured_place. to_string ( self . tcx ) ,
1044
+ } ) ;
1028
1045
}
1029
1046
ty:: UpvarCapture :: ByRef ( ..) => { }
1030
1047
}
1031
1048
}
1032
1049
1050
+ debug ! ( ?projections_list) ;
1051
+ debug ! ( ?diagnostics_info) ;
1052
+
1033
1053
let is_moved = !projections_list. is_empty ( ) ;
1054
+ debug ! ( ?is_moved) ;
1034
1055
1035
1056
let is_not_completely_captured =
1036
1057
root_var_min_capture_list. iter ( ) . any ( |capture| !capture. place . projections . is_empty ( ) ) ;
1058
+ debug ! ( ?is_not_completely_captured) ;
1037
1059
1038
1060
if is_moved
1039
1061
&& is_not_completely_captured
@@ -1066,6 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1066
1088
/// Returns a tuple containing a vector of MigrationDiagnosticInfo, as well as a String
1067
1089
/// containing the reason why root variables whose HirId is contained in the vector should
1068
1090
/// be captured
1091
+ #[ instrument( level = "debug" , skip( self ) ) ]
1069
1092
fn compute_2229_migrations (
1070
1093
& self ,
1071
1094
closure_def_id : DefId ,
@@ -1131,14 +1154,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1131
1154
// auto trait implementation issues
1132
1155
auto_trait_migration_reasons. extend ( capture_trait_reasons. clone ( ) ) ;
1133
1156
1134
- responsible_captured_hir_ids. push ( (
1135
- captured_info. 0 ,
1136
- captured_info. 1 . clone ( ) ,
1137
- self . compute_2229_migrations_reasons (
1138
- capture_trait_reasons,
1139
- capture_drop_reorder_reason,
1140
- ) ,
1141
- ) ) ;
1157
+ match captured_info {
1158
+ CapturesInfo :: CapturingLess { source_expr, var_name } => {
1159
+ responsible_captured_hir_ids. push ( (
1160
+ * source_expr,
1161
+ var_name. clone ( ) ,
1162
+ self . compute_2229_migrations_reasons (
1163
+ capture_trait_reasons,
1164
+ capture_drop_reorder_reason,
1165
+ ) ,
1166
+ ) ) ;
1167
+ }
1168
+ }
1142
1169
}
1143
1170
1144
1171
if !capture_diagnostic. is_empty ( ) {
@@ -2087,6 +2114,7 @@ fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol {
2087
2114
tcx. hir ( ) . name ( var_hir_id)
2088
2115
}
2089
2116
2117
+ #[ instrument( level = "debug" , skip( tcx) ) ]
2090
2118
fn should_do_rust_2021_incompatible_closure_captures_analysis (
2091
2119
tcx : TyCtxt < ' _ > ,
2092
2120
closure_id : hir:: HirId ,
0 commit comments