Skip to content

Commit bcda695

Browse files
committed
mir-borrowck: Move span_label calls for cannot_assign_to_borrowed() inside borrowck_errors.rs
1 parent d514263 commit bcda695

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,13 +865,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
865865
loan_path: &LoanPath<'tcx>,
866866
loan: &Loan) {
867867
self.bccx.cannot_assign_to_borrowed(
868-
span, &self.bccx.loan_path_to_string(loan_path), Origin::Ast)
869-
.span_label(loan.span,
870-
format!("borrow of `{}` occurs here",
871-
self.bccx.loan_path_to_string(loan_path)))
872-
.span_label(span,
873-
format!("assignment to borrowed `{}` occurs here",
874-
self.bccx.loan_path_to_string(loan_path)))
868+
span, loan.span, &self.bccx.loan_path_to_string(loan_path), Origin::Ast)
875869
.emit();
876870
}
877871
}

src/librustc_mir/borrow_check.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -991,14 +991,8 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
991991
_: Context,
992992
(lvalue, span): (&Lvalue, Span),
993993
loan: &BorrowData) {
994-
let describe_lvalue = self.describe_lvalue(lvalue);
995-
let borrow_span = self.retrieve_borrow_span(loan);
996-
997994
let mut err = self.tcx.cannot_assign_to_borrowed(
998-
span, &self.describe_lvalue(lvalue), Origin::Mir);
999-
1000-
err.span_label(borrow_span, format!("borrow of `{}` occurs here", describe_lvalue));
1001-
err.span_label(span, format!("assignment to borrowed `{}` occurs here", describe_lvalue));
995+
span, self.retrieve_borrow_span(loan), &self.describe_lvalue(lvalue), Origin::Mir);
1002996

1003997
err.emit();
1004998
}

src/librustc_mir/util/borrowck_errors.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ pub trait BorrowckErrors {
140140
desc_new, msg_new, kind_new, noun_old, kind_old, msg_old, OGN=o)
141141
}
142142

143-
fn cannot_assign_to_borrowed(&self, span: Span, desc: &str, o: Origin)
143+
fn cannot_assign_to_borrowed(&self, span: Span, borrow_span: Span, desc: &str, o: Origin)
144144
-> DiagnosticBuilder
145145
{
146-
struct_span_err!(self, span, E0506,
146+
let mut err = struct_span_err!(self, span, E0506,
147147
"cannot assign to `{}` because it is borrowed{OGN}",
148-
desc, OGN=o)
148+
desc, OGN=o);
149+
150+
err.span_label(borrow_span, format!("borrow of `{}` occurs here", desc));
151+
err.span_label(span, format!("assignment to borrowed `{}` occurs here", desc));
152+
153+
err
149154
}
150155

151156
fn cannot_move_into_closure(&self, span: Span, desc: &str, o: Origin)

0 commit comments

Comments
 (0)