@@ -475,99 +475,104 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
475475
476476 let mut err = match ( new_loan. kind , old_loan. kind ) {
477477 ( ty:: MutBorrow , ty:: MutBorrow ) => {
478- struct_span_err ! ( self . bccx, new_loan. span, E0499 ,
479- "cannot borrow `{}`{} as mutable \
480- more than once at a time",
481- nl, new_loan_msg)
482- . span_label (
478+ let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0499 ,
479+ "cannot borrow `{}`{} as mutable \
480+ more than once at a time",
481+ nl, new_loan_msg) ;
482+ err . span_label (
483483 old_loan. span ,
484- & format ! ( "first mutable borrow occurs here{}" , old_loan_msg) )
485- . span_label (
484+ & format ! ( "first mutable borrow occurs here{}" , old_loan_msg) ) ;
485+ err . span_label (
486486 new_loan. span ,
487- & format ! ( "second mutable borrow occurs here{}" , new_loan_msg) )
488- . span_label (
487+ & format ! ( "second mutable borrow occurs here{}" , new_loan_msg) ) ;
488+ err . span_label (
489489 previous_end_span,
490- & format ! ( "first borrow ends here" ) )
490+ & format ! ( "first borrow ends here" ) ) ;
491+ err
491492 }
492493
493494 ( ty:: UniqueImmBorrow , ty:: UniqueImmBorrow ) => {
494- struct_span_err ! ( self . bccx, new_loan. span, E0524 ,
495+ let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0524 ,
495496 "two closures require unique access to `{}` \
496497 at the same time",
497- nl)
498- . span_label (
498+ nl) ;
499+ err . span_label (
499500 old_loan. span ,
500- & format ! ( "first closure is constructed here" ) )
501- . span_label (
501+ & format ! ( "first closure is constructed here" ) ) ;
502+ err . span_label (
502503 new_loan. span ,
503- & format ! ( "second closure is constructed here" ) )
504- . span_label (
504+ & format ! ( "second closure is constructed here" ) ) ;
505+ err . span_label (
505506 previous_end_span,
506- & format ! ( "borrow from first closure ends here" ) )
507+ & format ! ( "borrow from first closure ends here" ) ) ;
508+ err
507509 }
508510
509511 ( ty:: UniqueImmBorrow , _) => {
510- struct_span_err ! ( self . bccx, new_loan. span, E0500 ,
511- "closure requires unique access to `{}` \
512- but {} is already borrowed{}",
513- nl, ol_pronoun, old_loan_msg)
514- . span_label (
512+ let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0500 ,
513+ "closure requires unique access to `{}` \
514+ but {} is already borrowed{}",
515+ nl, ol_pronoun, old_loan_msg) ;
516+ err . span_label (
515517 new_loan. span ,
516- & format ! ( "closure construction occurs here{}" , new_loan_msg) )
517- . span_label (
518+ & format ! ( "closure construction occurs here{}" , new_loan_msg) ) ;
519+ err . span_label (
518520 old_loan. span ,
519- & format ! ( "borrow occurs here{}" , old_loan_msg) )
520- . span_label (
521+ & format ! ( "borrow occurs here{}" , old_loan_msg) ) ;
522+ err . span_label (
521523 previous_end_span,
522- & format ! ( "borrow ends here" ) )
524+ & format ! ( "borrow ends here" ) ) ;
525+ err
523526 }
524527
525528 ( _, ty:: UniqueImmBorrow ) => {
526- struct_span_err ! ( self . bccx, new_loan. span, E0501 ,
527- "cannot borrow `{}`{} as {} because \
528- previous closure requires unique access",
529- nl, new_loan_msg, new_loan. kind. to_user_str( ) )
530- . span_label (
529+ let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0501 ,
530+ "cannot borrow `{}`{} as {} because \
531+ previous closure requires unique access",
532+ nl, new_loan_msg, new_loan. kind. to_user_str( ) ) ;
533+ err . span_label (
531534 new_loan. span ,
532- & format ! ( "borrow occurs here{}" , new_loan_msg) )
533- . span_label (
535+ & format ! ( "borrow occurs here{}" , new_loan_msg) ) ;
536+ err . span_label (
534537 old_loan. span ,
535- & format ! ( "closure construction occurs here{}" , old_loan_msg) )
536- . span_label (
538+ & format ! ( "closure construction occurs here{}" , old_loan_msg) ) ;
539+ err . span_label (
537540 previous_end_span,
538- & format ! ( "borrow from closure ends here" ) )
541+ & format ! ( "borrow from closure ends here" ) ) ;
542+ err
539543 }
540544
541545 ( _, _) => {
542- struct_span_err ! ( self . bccx, new_loan. span, E0502 ,
543- "cannot borrow `{}`{} as {} because \
544- {} is also borrowed as {}{}",
545- nl,
546- new_loan_msg,
547- new_loan. kind. to_user_str( ) ,
548- ol_pronoun,
549- old_loan. kind. to_user_str( ) ,
550- old_loan_msg)
551- . span_label (
546+ let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0502 ,
547+ "cannot borrow `{}`{} as {} because \
548+ {} is also borrowed as {}{}",
549+ nl,
550+ new_loan_msg,
551+ new_loan. kind. to_user_str( ) ,
552+ ol_pronoun,
553+ old_loan. kind. to_user_str( ) ,
554+ old_loan_msg) ;
555+ err . span_label (
552556 new_loan. span ,
553557 & format ! ( "{} borrow occurs here{}" ,
554558 new_loan. kind. to_user_str( ) ,
555- new_loan_msg) )
556- . span_label (
559+ new_loan_msg) ) ;
560+ err . span_label (
557561 old_loan. span ,
558562 & format ! ( "{} borrow occurs here{}" ,
559563 old_loan. kind. to_user_str( ) ,
560- old_loan_msg) )
561- . span_label (
564+ old_loan_msg) ) ;
565+ err . span_label (
562566 previous_end_span,
563567 & format ! ( "{} borrow ends here" ,
564- old_loan. kind. to_user_str( ) ) )
568+ old_loan. kind. to_user_str( ) ) ) ;
569+ err
565570 }
566571 } ;
567572
568573 match new_loan. cause {
569574 euv:: ClosureCapture ( span) => {
570- err = err . span_label (
575+ err. span_label (
571576 span,
572577 & format ! ( "borrow occurs due to use of `{}` in closure" , nl) ) ;
573578 }
@@ -576,7 +581,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
576581
577582 match old_loan. cause {
578583 euv:: ClosureCapture ( span) => {
579- err = err . span_label (
584+ err. span_label (
580585 span,
581586 & format ! ( "previous borrow occurs due to use of `{}` in closure" ,
582587 ol) ) ;
@@ -663,23 +668,41 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
663668 UseOk => { }
664669 UseWhileBorrowed ( loan_path, loan_span) => {
665670 let mut err = match move_kind {
666- move_data:: Captured =>
667- struct_span_err ! ( self . bccx, span, E0504 ,
671+ move_data:: Captured => {
672+ let mut err = struct_span_err ! ( self . bccx, span, E0504 ,
668673 "cannot move `{}` into closure because it is borrowed" ,
669- & self . bccx. loan_path_to_string( move_path) ) ,
674+ & self . bccx. loan_path_to_string( move_path) ) ;
675+ err. span_label (
676+ loan_span,
677+ & format ! ( "borrow of `{}` occurs here" ,
678+ & self . bccx. loan_path_to_string( & loan_path) )
679+ ) ;
680+ err. span_label (
681+ span,
682+ & format ! ( "move into closure occurs here" )
683+ ) ;
684+ err
685+ }
670686 move_data:: Declared |
671687 move_data:: MoveExpr |
672- move_data:: MovePat =>
673- struct_span_err ! ( self . bccx, span, E0505 ,
688+ move_data:: MovePat => {
689+ let mut err = struct_span_err ! ( self . bccx, span, E0505 ,
674690 "cannot move out of `{}` because it is borrowed" ,
675- & self . bccx. loan_path_to_string( move_path) )
691+ & self . bccx. loan_path_to_string( move_path) ) ;
692+ err. span_label (
693+ loan_span,
694+ & format ! ( "borrow of `{}` occurs here" ,
695+ & self . bccx. loan_path_to_string( & loan_path) )
696+ ) ;
697+ err. span_label (
698+ span,
699+ & format ! ( "move out of `{}` occurs here" ,
700+ & self . bccx. loan_path_to_string( move_path) )
701+ ) ;
702+ err
703+ }
676704 } ;
677705
678- err. span_note (
679- loan_span,
680- & format ! ( "borrow of `{}` occurs here" ,
681- & self . bccx. loan_path_to_string( & loan_path) )
682- ) ;
683706 err. emit ( ) ;
684707 }
685708 }
@@ -845,9 +868,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
845868 struct_span_err ! ( self . bccx, span, E0506 ,
846869 "cannot assign to `{}` because it is borrowed" ,
847870 self . bccx. loan_path_to_string( loan_path) )
848- . span_note ( loan. span ,
871+ . span_label ( loan. span ,
849872 & format ! ( "borrow of `{}` occurs here" ,
850873 self . bccx. loan_path_to_string( loan_path) ) )
874+ . span_label ( span,
875+ & format ! ( "assignment to `{}` occurs here" ,
876+ self . bccx. loan_path_to_string( loan_path) ) )
851877 . emit ( ) ;
852878 }
853879}
0 commit comments