diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index bf5bce8fc3ba3..c0c3d5ecd0abf 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -663,23 +663,39 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { UseOk => { } UseWhileBorrowed(loan_path, loan_span) => { let mut err = match move_kind { - move_data::Captured => + move_data::Captured => { struct_span_err!(self.bccx, span, E0504, "cannot move `{}` into closure because it is borrowed", - &self.bccx.loan_path_to_string(move_path)), + &self.bccx.loan_path_to_string(move_path)) + .span_label( + loan_span, + &format!("borrow of `{}` occurs here", + &self.bccx.loan_path_to_string(&loan_path)) + ) + .span_label( + span, + &format!("move into closure occurs here") + ) + } move_data::Declared | move_data::MoveExpr | - move_data::MovePat => + move_data::MovePat => { struct_span_err!(self.bccx, span, E0505, "cannot move out of `{}` because it is borrowed", &self.bccx.loan_path_to_string(move_path)) + .span_label( + loan_span, + &format!("borrow of `{}` occurs here", + &self.bccx.loan_path_to_string(&loan_path)) + ) + .span_label( + span, + &format!("move out of `{}` occurs here", + &self.bccx.loan_path_to_string(move_path)) + ) + } }; - err.span_note( - loan_span, - &format!("borrow of `{}` occurs here", - &self.bccx.loan_path_to_string(&loan_path)) - ); err.emit(); } } @@ -845,9 +861,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { struct_span_err!(self.bccx, span, E0506, "cannot assign to `{}` because it is borrowed", self.bccx.loan_path_to_string(loan_path)) - .span_note(loan.span, + .span_label(loan.span, &format!("borrow of `{}` occurs here", self.bccx.loan_path_to_string(loan_path))) + .span_label(span, + &format!("assignment to `{}` occurs here", + self.bccx.loan_path_to_string(loan_path))) .emit(); } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 5768a441c51b7..0f2381f1ff916 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -72,7 +72,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, let mut err = report_cannot_move_out_of(bccx, error.move_from.clone()); let mut is_first_note = true; for move_to in &error.move_to_places { - note_move_destination(&mut err, move_to.span, + err = note_move_destination(err, move_to.span, move_to.name, is_first_note); is_first_note = false; } @@ -124,6 +124,10 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, struct_span_err!(bccx, move_from.span, E0507, "cannot move out of {}", move_from.descriptive_string(bccx.tcx)) + .span_label( + move_from.span, + &format!("move occurs here") + ) } Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => { @@ -159,22 +163,24 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, } } -fn note_move_destination(err: &mut DiagnosticBuilder, +fn note_move_destination(mut err: DiagnosticBuilder, move_to_span: codemap::Span, pat_name: ast::Name, - is_first_note: bool) { + is_first_note: bool) -> DiagnosticBuilder { if is_first_note { - err.span_note( + err = err.span_label( move_to_span, - "attempting to move value to here"); + &format!("attempting to move value to here")); err.help( &format!("to prevent the move, \ use `ref {0}` or `ref mut {0}` to capture value by \ reference", pat_name)); + err } else { err.span_note(move_to_span, &format!("and here (use `ref {0}` or `ref mut {0}`)", pat_name)); + err } } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index f0ea69c8a6b3d..e5fb08b36bf7e 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -620,11 +620,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } // General fallback. + let span = err.span.clone(); let mut db = self.struct_span_err( err.span, &self.bckerr_to_string(&err)); self.note_and_explain_bckerr(&mut db, err); - db.emit(); + db.span_label(span, &format!("cannot borrow")) + .emit(); } pub fn report_use_of_moved_value(&self, @@ -647,7 +649,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx.sess, use_span, E0381, "{} of possibly uninitialized variable: `{}`", verb, - self.loan_path_to_string(lp)).emit(); + self.loan_path_to_string(lp)) + .span_label(use_span, &format!("use of possibly uninitialized `{}`", + self.loan_path_to_string(lp))) + .emit(); return; } _ => { diff --git a/src/libsyntax/errors/snippet/mod.rs b/src/libsyntax/errors/snippet/mod.rs index 237e6823e0f87..4070a666ef6c1 100644 --- a/src/libsyntax/errors/snippet/mod.rs +++ b/src/libsyntax/errors/snippet/mod.rs @@ -612,6 +612,7 @@ impl FileInfo { styled_buffer.set_style(0, p, Style::UnderlinePrimary); } else { styled_buffer.putc(1, p, '-', Style::UnderlineSecondary); + styled_buffer.set_style(0, p, Style::UnderlineSecondary); } } }