@@ -223,18 +223,24 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
223223
224224 fn report ( & mut self , error : GroupedMoveError < ' tcx > ) {
225225 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+ ) =
227233 match error {
228234 GroupedMoveError :: MovesFromPlace { span, ref original_path, ref kind, .. } |
229235 GroupedMoveError :: MovesFromValue { span, ref original_path, ref kind, .. } => {
230- ( span, original_path, kind)
236+ ( span, None , original_path, kind)
231237 }
232238 GroupedMoveError :: OtherIllegalMove {
233239 use_spans,
234240 ref original_path,
235241 ref kind
236242 } => {
237- ( use_spans. args_or_use ( ) , original_path, kind)
243+ ( use_spans. args_or_use ( ) , Some ( use_spans ) , original_path, kind)
238244 } ,
239245 } ;
240246 debug ! ( "report: original_path={:?} span={:?}, kind={:?} \
@@ -250,6 +256,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
250256 original_path,
251257 target_place,
252258 span,
259+ use_spans,
253260 )
254261 }
255262 IllegalMoveOriginKind :: InteriorOfTypeWithDestructor { container_ty : ty } => {
@@ -296,6 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
296303 move_place : & Place < ' tcx > ,
297304 deref_target_place : & Place < ' tcx > ,
298305 span : Span ,
306+ use_spans : Option < UseSpans > ,
299307 ) -> DiagnosticBuilder < ' a > {
300308 // Inspect the type of the content behind the
301309 // borrow to provide feedback about why this
@@ -416,7 +424,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
416424 if let Ok ( snippet) = self . infcx . tcx . sess . source_map ( ) . span_to_snippet ( span) {
417425 let is_option = move_ty. starts_with ( "std::option::Option" ) ;
418426 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 ( ) ) {
420428 err. span_suggestion (
421429 span,
422430 & format ! ( "consider borrowing the `{}`'s content" , if is_option {
0 commit comments