@@ -130,6 +130,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
130
130
let partial_str = if is_partial_move { "partial " } else { "" } ;
131
131
let partially_str = if is_partial_move { "partially " } else { "" } ;
132
132
133
+ let mpi = self . move_data . moves [ move_out_indices[ 0 ] ] . path ;
134
+ let place = & self . move_data . move_paths [ mpi] . place ;
135
+ let ty = place. ty ( self . body , self . infcx . tcx ) . ty ;
136
+
133
137
let mut err = self . cannot_act_on_moved_value (
134
138
span,
135
139
desired_action. as_noun ( ) ,
@@ -186,6 +190,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
186
190
} else {
187
191
""
188
192
} ;
193
+ let suggest_clone = self . suggest_using_clone ( ty) && !move_spans. for_closure ( ) ;
189
194
190
195
if location == move_out. source {
191
196
is_loop_move = true ;
@@ -202,6 +207,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
202
207
move_msg,
203
208
is_loop_move,
204
209
maybe_reinitialized_locations. is_empty ( ) ,
210
+ suggest_clone,
205
211
) ;
206
212
207
213
if let ( UseSpans :: PatUse ( span) , [ ] ) =
@@ -237,8 +243,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
237
243
) ;
238
244
}
239
245
240
- let ty = used_place. ty ( self . body , self . infcx . tcx ) . ty ;
241
- let needs_note = match ty . kind ( ) {
246
+ let used_ty = used_place. ty ( self . body , self . infcx . tcx ) . ty ;
247
+ let needs_note = match used_ty . kind ( ) {
242
248
ty:: Closure ( id, _) => {
243
249
let tables = self . infcx . tcx . typeck ( id. expect_local ( ) ) ;
244
250
let hir_id = self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( id. expect_local ( ) ) ;
@@ -248,10 +254,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
248
254
_ => true ,
249
255
} ;
250
256
251
- let mpi = self . move_data . moves [ move_out_indices[ 0 ] ] . path ;
252
- let place = & self . move_data . move_paths [ mpi] . place ;
253
- let ty = place. ty ( self . body , self . infcx . tcx ) . ty ;
254
-
255
257
// If we're in pattern, we do nothing in favor of the previous suggestion (#80913).
256
258
// Same for if we're in a loop, see #101119.
257
259
if is_loop_move & !in_pattern && !matches ! ( use_spans, UseSpans :: ClosureUse { .. } ) {
0 commit comments