@@ -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,6 +1004,7 @@ 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
@@ -1006,7 +1014,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1006
1014
root_var_min_capture_list
1007
1015
} else {
1008
1016
// The upvar is mentioned within the closure but no path starting from it is
1009
- // used.
1017
+ // used. This occurs when you have (e.g.)
1018
+ //
1019
+ // ```
1020
+ // let x = move || {
1021
+ // let _ = y;
1022
+ // });
1023
+ // ```
1024
+ debug ! ( "no path starting from it is used" ) ;
1025
+
1010
1026
1011
1027
match closure_clause {
1012
1028
// Only migrate if closure is a move closure
@@ -1016,6 +1032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1016
1032
1017
1033
return None ;
1018
1034
} ;
1035
+ debug ! ( ?root_var_min_capture_list) ;
1019
1036
1020
1037
let mut projections_list = Vec :: new ( ) ;
1021
1038
let mut diagnostics_info = FxHashSet :: default ( ) ;
@@ -1025,19 +1042,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1025
1042
// Only care about captures that are moved into the closure
1026
1043
ty:: UpvarCapture :: ByValue ( ..) => {
1027
1044
projections_list. push ( captured_place. place . projections . as_slice ( ) ) ;
1028
- diagnostics_info. insert ( (
1029
- captured_place. info . path_expr_id ,
1030
- captured_place. to_string ( self . tcx ) ,
1031
- ) ) ;
1045
+ diagnostics_info. insert ( CapturesInfo :: CapturingLess {
1046
+ source_expr : captured_place. info . path_expr_id ,
1047
+ var_name : captured_place. to_string ( self . tcx ) ,
1048
+ } ) ;
1032
1049
}
1033
1050
ty:: UpvarCapture :: ByRef ( ..) => { }
1034
1051
}
1035
1052
}
1036
1053
1054
+ debug ! ( ?projections_list) ;
1055
+ debug ! ( ?diagnostics_info) ;
1056
+
1037
1057
let is_moved = !projections_list. is_empty ( ) ;
1058
+ debug ! ( ?is_moved) ;
1038
1059
1039
1060
let is_not_completely_captured =
1040
1061
root_var_min_capture_list. iter ( ) . any ( |capture| !capture. place . projections . is_empty ( ) ) ;
1062
+ debug ! ( ?is_not_completely_captured) ;
1041
1063
1042
1064
if is_moved
1043
1065
&& is_not_completely_captured
@@ -1070,6 +1092,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1070
1092
/// Returns a tuple containing a vector of MigrationDiagnosticInfo, as well as a String
1071
1093
/// containing the reason why root variables whose HirId is contained in the vector should
1072
1094
/// be captured
1095
+ #[ instrument( level = "debug" , skip( self ) ) ]
1073
1096
fn compute_2229_migrations (
1074
1097
& self ,
1075
1098
closure_def_id : DefId ,
@@ -1137,14 +1160,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1137
1160
// auto trait implementation issues
1138
1161
auto_trait_migration_reasons. extend ( capture_trait_reasons. clone ( ) ) ;
1139
1162
1140
- responsible_captured_hir_ids. push ( (
1141
- captured_info. 0 ,
1142
- captured_info. 1 . clone ( ) ,
1143
- self . compute_2229_migrations_reasons (
1144
- capture_trait_reasons,
1145
- capture_drop_reorder_reason,
1146
- ) ,
1147
- ) ) ;
1163
+ match captured_info {
1164
+ CapturesInfo :: CapturingLess { source_expr, var_name } => {
1165
+ responsible_captured_hir_ids. push ( (
1166
+ * source_expr,
1167
+ var_name. clone ( ) ,
1168
+ self . compute_2229_migrations_reasons (
1169
+ capture_trait_reasons,
1170
+ capture_drop_reorder_reason,
1171
+ ) ,
1172
+ ) ) ;
1173
+ }
1174
+ }
1148
1175
}
1149
1176
1150
1177
if !capture_diagnostic. is_empty ( ) {
@@ -2095,6 +2122,7 @@ fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol {
2095
2122
tcx. hir ( ) . name ( var_hir_id)
2096
2123
}
2097
2124
2125
+ #[ instrument( level = "debug" , skip( tcx) ) ]
2098
2126
fn should_do_rust_2021_incompatible_closure_captures_analysis (
2099
2127
tcx : TyCtxt < ' _ > ,
2100
2128
closure_id : hir:: HirId ,
0 commit comments