about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBasile Desloges <basile.desloges@gmail.com>2017-09-28 16:45:09 +0200
committerBasile Desloges <basile.desloges@gmail.com>2017-09-29 15:41:26 +0200
commit5c8066b4a735f952cf1223c903c1bdd7ea606b81 (patch)
treeda35ccff371f826cf56af08573e1c64ee6fc0329
parentbcda69572064cfcc679ac4dc7ad0b0a369e3b861 (diff)
downloadrust-5c8066b4a735f952cf1223c903c1bdd7ea606b81.tar.gz
rust-5c8066b4a735f952cf1223c903c1bdd7ea606b81.zip
mir-borrowck: Move span_label calls for `cannot_use_when_mutably_borrowed()` inside `borrowck_errors.rs`
-rw-r--r--src/librustc_borrowck/borrowck/check_loans.rs12
-rw-r--r--src/librustc_mir/borrow_check.rs9
-rw-r--r--src/librustc_mir/util/borrowck_errors.rs16
3 files changed, 20 insertions, 17 deletions
diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs
index 0036a74c861..834bde660a8 100644
--- a/src/librustc_borrowck/borrowck/check_loans.rs
+++ b/src/librustc_borrowck/borrowck/check_loans.rs
@@ -640,14 +640,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
             UseOk => { }
             UseWhileBorrowed(loan_path, loan_span) => {
                 let desc = self.bccx.loan_path_to_string(copy_path);
-                self.bccx.cannot_use_when_mutably_borrowed(span, &desc, Origin::Ast)
-                    .span_label(loan_span,
-                               format!("borrow of `{}` occurs here",
-                                       &self.bccx.loan_path_to_string(&loan_path))
-                               )
-                    .span_label(span,
-                               format!("use of borrowed `{}`",
-                                        &self.bccx.loan_path_to_string(&loan_path)))
+                self.bccx.cannot_use_when_mutably_borrowed(
+                        span, &desc,
+                        loan_span, &self.bccx.loan_path_to_string(&loan_path),
+                        Origin::Ast)
                     .emit();
             }
         }
diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs
index d2ab00a46c7..b38df4416e8 100644
--- a/src/librustc_mir/borrow_check.rs
+++ b/src/librustc_mir/borrow_check.rs
@@ -931,14 +931,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
                                          _context: Context,
                                          (lvalue, span): (&Lvalue, Span),
                                          borrow : &BorrowData) {
-        let described_lvalue = self.describe_lvalue(lvalue);
-        let borrow_span = self.retrieve_borrow_span(borrow);
 
         let mut err = self.tcx.cannot_use_when_mutably_borrowed(
-            span, &described_lvalue, Origin::Mir);
-
-        err.span_label(borrow_span, format!("borrow of `{}` occurs here", described_lvalue));
-        err.span_label(span, format!("use of borrowed `{}`", described_lvalue));
+            span, &self.describe_lvalue(lvalue),
+            self.retrieve_borrow_span(borrow), &self.describe_lvalue(&borrow.lvalue),
+            Origin::Mir);
 
         err.emit();
     }
diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs
index 7aec361e892..3b96ac3f2e7 100644
--- a/src/librustc_mir/util/borrowck_errors.rs
+++ b/src/librustc_mir/util/borrowck_errors.rs
@@ -57,12 +57,22 @@ pub trait BorrowckErrors {
                          desc, OGN=o)
     }
 
-    fn cannot_use_when_mutably_borrowed(&self, span: Span, desc: &str, o: Origin)
+    fn cannot_use_when_mutably_borrowed(&self,
+                                        span: Span,
+                                        desc: &str,
+                                        borrow_span: Span,
+                                        borrow_desc: &str,
+                                        o: Origin)
                                         -> DiagnosticBuilder
     {
-        struct_span_err!(self, span, E0503,
+        let mut err = struct_span_err!(self, span, E0503,
                          "cannot use `{}` because it was mutably borrowed{OGN}",
-                         desc, OGN=o)
+                         desc, OGN=o);
+
+        err.span_label(borrow_span, format!("borrow of `{}` occurs here", borrow_desc));
+        err.span_label(span, format!("use of borrowed `{}`", borrow_desc));
+
+        err
     }
 
     fn cannot_act_on_uninitialized_variable(&self,