@@ -223,18 +223,24 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
223
223
224
224
fn report ( & mut self , error : GroupedMoveError < ' tcx > ) {
225
225
let ( mut err, err_span) = {
226
- let ( span, original_path, kind) : ( Span , & Place < ' tcx > , & IllegalMoveOriginKind < ' _ > ) =
226
+ let ( span, use_spans, original_path, kind, ) :
227
+ (
228
+ Span ,
229
+ Option < UseSpans > ,
230
+ & Place < ' tcx > ,
231
+ & IllegalMoveOriginKind < ' _ > ,
232
+ ) =
227
233
match error {
228
234
GroupedMoveError :: MovesFromPlace { span, ref original_path, ref kind, .. } |
229
235
GroupedMoveError :: MovesFromValue { span, ref original_path, ref kind, .. } => {
230
- ( span, original_path, kind)
236
+ ( span, None , original_path, kind)
231
237
}
232
238
GroupedMoveError :: OtherIllegalMove {
233
239
use_spans,
234
240
ref original_path,
235
241
ref kind
236
242
} => {
237
- ( use_spans. args_or_use ( ) , original_path, kind)
243
+ ( use_spans. args_or_use ( ) , Some ( use_spans ) , original_path, kind)
238
244
} ,
239
245
} ;
240
246
debug ! ( "report: original_path={:?} span={:?}, kind={:?} \
@@ -250,6 +256,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
250
256
original_path,
251
257
target_place,
252
258
span,
259
+ use_spans,
253
260
)
254
261
}
255
262
IllegalMoveOriginKind :: InteriorOfTypeWithDestructor { container_ty : ty } => {
@@ -296,6 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
296
303
move_place : & Place < ' tcx > ,
297
304
deref_target_place : & Place < ' tcx > ,
298
305
span : Span ,
306
+ use_spans : Option < UseSpans > ,
299
307
) -> DiagnosticBuilder < ' a > {
300
308
// Inspect the type of the content behind the
301
309
// borrow to provide feedback about why this
@@ -416,7 +424,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
416
424
if let Ok ( snippet) = self . infcx . tcx . sess . source_map ( ) . span_to_snippet ( span) {
417
425
let is_option = move_ty. starts_with ( "std::option::Option" ) ;
418
426
let is_result = move_ty. starts_with ( "std::result::Result" ) ;
419
- if is_option || is_result {
427
+ if ( is_option || is_result) && use_spans . map_or ( true , |v| !v . for_closure ( ) ) {
420
428
err. span_suggestion (
421
429
span,
422
430
& format ! ( "consider borrowing the `{}`'s content" , if is_option {
0 commit comments