@@ -475,99 +475,104 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
475
475
476
476
let mut err = match ( new_loan. kind , old_loan. kind ) {
477
477
( 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 (
483
483
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 (
486
486
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 (
489
489
previous_end_span,
490
- & format ! ( "first borrow ends here" ) )
490
+ & format ! ( "first borrow ends here" ) ) ;
491
+ err
491
492
}
492
493
493
494
( 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 ,
495
496
"two closures require unique access to `{}` \
496
497
at the same time",
497
- nl)
498
- . span_label (
498
+ nl) ;
499
+ err . span_label (
499
500
old_loan. span ,
500
- & format ! ( "first closure is constructed here" ) )
501
- . span_label (
501
+ & format ! ( "first closure is constructed here" ) ) ;
502
+ err . span_label (
502
503
new_loan. span ,
503
- & format ! ( "second closure is constructed here" ) )
504
- . span_label (
504
+ & format ! ( "second closure is constructed here" ) ) ;
505
+ err . span_label (
505
506
previous_end_span,
506
- & format ! ( "borrow from first closure ends here" ) )
507
+ & format ! ( "borrow from first closure ends here" ) ) ;
508
+ err
507
509
}
508
510
509
511
( 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 (
515
517
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 (
518
520
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 (
521
523
previous_end_span,
522
- & format ! ( "borrow ends here" ) )
524
+ & format ! ( "borrow ends here" ) ) ;
525
+ err
523
526
}
524
527
525
528
( _, 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 (
531
534
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 (
534
537
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 (
537
540
previous_end_span,
538
- & format ! ( "borrow from closure ends here" ) )
541
+ & format ! ( "borrow from closure ends here" ) ) ;
542
+ err
539
543
}
540
544
541
545
( _, _) => {
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 (
552
556
new_loan. span ,
553
557
& format ! ( "{} borrow occurs here{}" ,
554
558
new_loan. kind. to_user_str( ) ,
555
- new_loan_msg) )
556
- . span_label (
559
+ new_loan_msg) ) ;
560
+ err . span_label (
557
561
old_loan. span ,
558
562
& format ! ( "{} borrow occurs here{}" ,
559
563
old_loan. kind. to_user_str( ) ,
560
- old_loan_msg) )
561
- . span_label (
564
+ old_loan_msg) ) ;
565
+ err . span_label (
562
566
previous_end_span,
563
567
& format ! ( "{} borrow ends here" ,
564
- old_loan. kind. to_user_str( ) ) )
568
+ old_loan. kind. to_user_str( ) ) ) ;
569
+ err
565
570
}
566
571
} ;
567
572
568
573
match new_loan. cause {
569
574
euv:: ClosureCapture ( span) => {
570
- err = err . span_label (
575
+ err. span_label (
571
576
span,
572
577
& format ! ( "borrow occurs due to use of `{}` in closure" , nl) ) ;
573
578
}
@@ -576,7 +581,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
576
581
577
582
match old_loan. cause {
578
583
euv:: ClosureCapture ( span) => {
579
- err = err . span_label (
584
+ err. span_label (
580
585
span,
581
586
& format ! ( "previous borrow occurs due to use of `{}` in closure" ,
582
587
ol) ) ;
@@ -663,23 +668,41 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
663
668
UseOk => { }
664
669
UseWhileBorrowed ( loan_path, loan_span) => {
665
670
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 ,
668
673
"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
+ }
670
686
move_data:: Declared |
671
687
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 ,
674
690
"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
+ }
676
704
} ;
677
705
678
- err. span_note (
679
- loan_span,
680
- & format ! ( "borrow of `{}` occurs here" ,
681
- & self . bccx. loan_path_to_string( & loan_path) )
682
- ) ;
683
706
err. emit ( ) ;
684
707
}
685
708
}
@@ -845,9 +868,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
845
868
struct_span_err ! ( self . bccx, span, E0506 ,
846
869
"cannot assign to `{}` because it is borrowed" ,
847
870
self . bccx. loan_path_to_string( loan_path) )
848
- . span_note ( loan. span ,
871
+ . span_label ( loan. span ,
849
872
& format ! ( "borrow of `{}` occurs here" ,
850
873
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) ) )
851
877
. emit ( ) ;
852
878
}
853
879
}
0 commit comments