@@ -29,6 +29,7 @@ use rustc::ty::{self, TyCtxt};
29
29
use syntax:: ast;
30
30
use syntax_pos:: Span ;
31
31
use rustc:: hir;
32
+ use rustc_mir:: util:: borrowck_errors:: { BorrowckErrors , Origin } ;
32
33
33
34
use std:: rc:: Rc ;
34
35
@@ -465,10 +466,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
465
466
466
467
let mut err = match ( new_loan. kind , old_loan. kind ) {
467
468
( ty:: MutBorrow , ty:: MutBorrow ) => {
468
- let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0499 ,
469
- "cannot borrow `{}`{} as mutable \
470
- more than once at a time",
471
- nl, new_loan_msg) ;
469
+ let mut err = self . bccx . cannot_mutably_borrow_multiply (
470
+ new_loan. span , & nl, & new_loan_msg, Origin :: Ast ) ;
472
471
473
472
if new_loan. span == old_loan. span {
474
473
// Both borrows are happening in the same place
@@ -496,10 +495,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
496
495
}
497
496
498
497
( ty:: UniqueImmBorrow , ty:: UniqueImmBorrow ) => {
499
- let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0524 ,
500
- "two closures require unique access to `{}` \
501
- at the same time",
502
- nl) ;
498
+ let mut err = self . bccx . cannot_uniquely_borrow_by_two_closures (
499
+ new_loan. span , & nl, Origin :: Ast ) ;
503
500
err. span_label (
504
501
old_loan. span ,
505
502
"first closure is constructed here" ) ;
@@ -513,10 +510,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
513
510
}
514
511
515
512
( ty:: UniqueImmBorrow , _) => {
516
- let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0500 ,
517
- "closure requires unique access to `{}` \
518
- but {} is already borrowed{}",
519
- nl, ol_pronoun, old_loan_msg) ;
513
+ let mut err = self . bccx . cannot_uniquely_borrow_by_one_closure (
514
+ new_loan. span , & nl, & ol_pronoun, & old_loan_msg, Origin :: Ast ) ;
520
515
err. span_label (
521
516
new_loan. span ,
522
517
format ! ( "closure construction occurs here{}" , new_loan_msg) ) ;
@@ -530,10 +525,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
530
525
}
531
526
532
527
( _, ty:: UniqueImmBorrow ) => {
533
- let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0501 ,
534
- "cannot borrow `{}`{} as {} because \
535
- previous closure requires unique access",
536
- nl, new_loan_msg, new_loan. kind. to_user_str( ) ) ;
528
+ let new_loan_str = & new_loan. kind . to_user_str ( ) ;
529
+ let mut err = self . bccx . cannot_reborrow_already_uniquely_borrowed (
530
+ new_loan. span , & nl, & new_loan_msg, new_loan_str, Origin :: Ast ) ;
537
531
err. span_label (
538
532
new_loan. span ,
539
533
format ! ( "borrow occurs here{}" , new_loan_msg) ) ;
@@ -547,15 +541,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
547
541
}
548
542
549
543
( ..) => {
550
- let mut err = struct_span_err ! ( self . bccx, new_loan. span, E0502 ,
551
- "cannot borrow `{}`{} as {} because \
552
- {} is also borrowed as {}{}",
553
- nl,
554
- new_loan_msg,
555
- new_loan. kind. to_user_str( ) ,
556
- ol_pronoun,
557
- old_loan. kind. to_user_str( ) ,
558
- old_loan_msg) ;
544
+ let mut err = self . bccx . cannot_reborrow_already_borrowed (
545
+ new_loan. span ,
546
+ & nl, & new_loan_msg, & new_loan. kind . to_user_str ( ) ,
547
+ & ol_pronoun, & old_loan. kind . to_user_str ( ) , & old_loan_msg, Origin :: Ast ) ;
559
548
err. span_label (
560
549
new_loan. span ,
561
550
format ! ( "{} borrow occurs here{}" ,
@@ -645,9 +634,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
645
634
match self . analyze_restrictions_on_use ( id, copy_path, ty:: ImmBorrow ) {
646
635
UseOk => { }
647
636
UseWhileBorrowed ( loan_path, loan_span) => {
648
- struct_span_err ! ( self . bccx, span, E0503 ,
649
- "cannot use `{}` because it was mutably borrowed" ,
650
- & self . bccx. loan_path_to_string( copy_path) )
637
+ let desc = self . bccx . loan_path_to_string ( copy_path) ;
638
+ self . bccx . cannot_use_when_mutably_borrowed ( span, & desc, Origin :: Ast )
651
639
. span_label ( loan_span,
652
640
format ! ( "borrow of `{}` occurs here" ,
653
641
& self . bccx. loan_path_to_string( & loan_path) )
@@ -673,9 +661,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
673
661
UseWhileBorrowed ( loan_path, loan_span) => {
674
662
let mut err = match move_kind {
675
663
move_data:: Captured => {
676
- let mut err = struct_span_err ! ( self . bccx, span, E0504 ,
677
- "cannot move `{}` into closure because it is borrowed" ,
678
- & self . bccx. loan_path_to_string( move_path) ) ;
664
+ let mut err = self . bccx . cannot_move_into_closure (
665
+ span, & self . bccx . loan_path_to_string ( move_path) , Origin :: Ast ) ;
679
666
err. span_label (
680
667
loan_span,
681
668
format ! ( "borrow of `{}` occurs here" ,
@@ -690,9 +677,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
690
677
move_data:: Declared |
691
678
move_data:: MoveExpr |
692
679
move_data:: MovePat => {
693
- let mut err = struct_span_err ! ( self . bccx, span, E0505 ,
694
- "cannot move out of `{}` because it is borrowed" ,
695
- & self . bccx. loan_path_to_string( move_path) ) ;
680
+ let desc = self . bccx . loan_path_to_string ( move_path) ;
681
+ let mut err = self . bccx . cannot_move_when_borrowed ( span, & desc, Origin :: Ast ) ;
696
682
err. span_label (
697
683
loan_span,
698
684
format ! ( "borrow of `{}` occurs here" ,
@@ -874,9 +860,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
874
860
span : Span ,
875
861
loan_path : & LoanPath < ' tcx > ,
876
862
loan : & Loan ) {
877
- struct_span_err ! ( self . bccx, span, E0506 ,
878
- "cannot assign to `{}` because it is borrowed" ,
879
- self . bccx. loan_path_to_string( loan_path) )
863
+ self . bccx . cannot_assign_to_borrowed (
864
+ span, & self . bccx . loan_path_to_string ( loan_path) , Origin :: Ast )
880
865
. span_label ( loan. span ,
881
866
format ! ( "borrow of `{}` occurs here" ,
882
867
self . bccx. loan_path_to_string( loan_path) ) )
0 commit comments