1
Fork 0

Set of fixes to improve borrowcks that weren't updated

This commit is contained in:
Jonathan Turner 2016-05-09 14:20:59 -07:00
parent e37f8593e4
commit f3054ce18c
4 changed files with 47 additions and 16 deletions

View file

@ -663,23 +663,39 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
UseOk => { } UseOk => { }
UseWhileBorrowed(loan_path, loan_span) => { UseWhileBorrowed(loan_path, loan_span) => {
let mut err = match move_kind { let mut err = match move_kind {
move_data::Captured => move_data::Captured => {
struct_span_err!(self.bccx, span, E0504, struct_span_err!(self.bccx, span, E0504,
"cannot move `{}` into closure because it is borrowed", "cannot move `{}` into closure because it is borrowed",
&self.bccx.loan_path_to_string(move_path)),
move_data::Declared |
move_data::MoveExpr |
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)) &self.bccx.loan_path_to_string(move_path))
}; .span_label(
err.span_note(
loan_span, loan_span,
&format!("borrow of `{}` occurs here", &format!("borrow of `{}` occurs here",
&self.bccx.loan_path_to_string(&loan_path)) &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 => {
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.emit(); err.emit();
} }
} }
@ -845,9 +861,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
struct_span_err!(self.bccx, span, E0506, struct_span_err!(self.bccx, span, E0506,
"cannot assign to `{}` because it is borrowed", "cannot assign to `{}` because it is borrowed",
self.bccx.loan_path_to_string(loan_path)) self.bccx.loan_path_to_string(loan_path))
.span_note(loan.span, .span_label(loan.span,
&format!("borrow of `{}` occurs here", &format!("borrow of `{}` occurs here",
self.bccx.loan_path_to_string(loan_path))) 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(); .emit();
} }
} }

View file

@ -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 err = report_cannot_move_out_of(bccx, error.move_from.clone());
let mut is_first_note = true; let mut is_first_note = true;
for move_to in &error.move_to_places { 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); move_to.name, is_first_note);
is_first_note = false; 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, struct_span_err!(bccx, move_from.span, E0507,
"cannot move out of {}", "cannot move out of {}",
move_from.descriptive_string(bccx.tcx)) move_from.descriptive_string(bccx.tcx))
.span_label(
move_from.span,
&format!("move occurs here")
)
} }
Categorization::Interior(ref b, mc::InteriorElement(Kind::Index, _)) => { 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, move_to_span: codemap::Span,
pat_name: ast::Name, pat_name: ast::Name,
is_first_note: bool) { is_first_note: bool) -> DiagnosticBuilder {
if is_first_note { if is_first_note {
err.span_note( err = err.span_label(
move_to_span, move_to_span,
"attempting to move value to here"); &format!("attempting to move value to here"));
err.help( err.help(
&format!("to prevent the move, \ &format!("to prevent the move, \
use `ref {0}` or `ref mut {0}` to capture value by \ use `ref {0}` or `ref mut {0}` to capture value by \
reference", reference",
pat_name)); pat_name));
err
} else { } else {
err.span_note(move_to_span, err.span_note(move_to_span,
&format!("and here (use `ref {0}` or `ref mut {0}`)", &format!("and here (use `ref {0}` or `ref mut {0}`)",
pat_name)); pat_name));
err
} }
} }

View file

@ -620,11 +620,13 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
// General fallback. // General fallback.
let span = err.span.clone();
let mut db = self.struct_span_err( let mut db = self.struct_span_err(
err.span, err.span,
&self.bckerr_to_string(&err)); &self.bckerr_to_string(&err));
self.note_and_explain_bckerr(&mut db, 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, pub fn report_use_of_moved_value(&self,
@ -647,7 +649,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
self.tcx.sess, use_span, E0381, self.tcx.sess, use_span, E0381,
"{} of possibly uninitialized variable: `{}`", "{} of possibly uninitialized variable: `{}`",
verb, 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; return;
} }
_ => { _ => {

View file

@ -612,6 +612,7 @@ impl FileInfo {
styled_buffer.set_style(0, p, Style::UnderlinePrimary); styled_buffer.set_style(0, p, Style::UnderlinePrimary);
} else { } else {
styled_buffer.putc(1, p, '-', Style::UnderlineSecondary); styled_buffer.putc(1, p, '-', Style::UnderlineSecondary);
styled_buffer.set_style(0, p, Style::UnderlineSecondary);
} }
} }
} }