Rollup merge of #44795 - KiChjang:mir-err-notes, r=arielb1

MIR borrowck: Add span labels for E0381 and E0505

Corresponds to `report_use_of_moved` and `report_move_out_when_borrowed`.

Part of #44596.
This commit is contained in:
Guillaume Gomez 2017-09-24 14:01:52 +02:00 committed by GitHub
commit a8a0ec2a28
1 changed files with 19 additions and 11 deletions

View File

@ -408,7 +408,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
self.each_borrow_involving_path( self.each_borrow_involving_path(
context, lvalue_span.0, flow_state, |this, _idx, borrow| { context, lvalue_span.0, flow_state, |this, _idx, borrow| {
if !borrow.compatible_with(BorrowKind::Mut) { if !borrow.compatible_with(BorrowKind::Mut) {
this.report_move_out_while_borrowed(context, lvalue_span); this.report_move_out_while_borrowed(context, lvalue_span, borrow);
Control::Break Control::Break
} else { } else {
Control::Continue Control::Continue
@ -896,20 +896,28 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
fn report_use_of_moved(&mut self, fn report_use_of_moved(&mut self,
_context: Context, _context: Context,
(lvalue, span): (&Lvalue, Span)) { (lvalue, span): (&Lvalue, Span)) {
let mut err = self.tcx.cannot_act_on_uninitialized_variable( self.tcx.cannot_act_on_uninitialized_variable(span,
span, "use", &self.describe_lvalue(lvalue), Origin::Mir); "use",
// FIXME: add span_label for use of uninitialized variable &self.describe_lvalue(lvalue),
err.emit(); Origin::Mir)
.span_label(span, format!("use of possibly uninitialized `{}`",
self.describe_lvalue(lvalue)))
.emit();
} }
fn report_move_out_while_borrowed(&mut self, fn report_move_out_while_borrowed(&mut self,
_context: Context, _context: Context,
(lvalue, span): (&Lvalue, Span)) { (lvalue, span): (&Lvalue, Span),
let mut err = self.tcx.cannot_move_when_borrowed( borrow: &BorrowData) {
span, &self.describe_lvalue(lvalue), Origin::Mir); self.tcx.cannot_move_when_borrowed(span,
// FIXME 1: add span_label for "borrow of `()` occurs here" &self.describe_lvalue(lvalue),
// FIXME 2: add span_label for "move out of `{}` occurs here" Origin::Mir)
err.emit(); .span_label(self.retrieve_borrow_span(borrow),
format!("borrow of `{}` occurs here",
self.describe_lvalue(&borrow.lvalue)))
.span_label(span, format!("move out of `{}` occurs here",
self.describe_lvalue(lvalue)))
.emit();
} }
fn report_use_while_mutably_borrowed(&mut self, fn report_use_while_mutably_borrowed(&mut self,