Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR borrowck: Add span labels for E0381 and E0505 #44795

Merged
merged 2 commits into from
Sep 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/librustc_mir/borrow_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
self.each_borrow_involving_path(
context, lvalue_span.0, flow_state, |this, _idx, borrow| {
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
} else {
Control::Continue
Expand Down Expand Up @@ -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,
_context: Context,
(lvalue, span): (&Lvalue, Span)) {
let mut err = self.tcx.cannot_act_on_uninitialized_variable(
span, "use", &self.describe_lvalue(lvalue), Origin::Mir);
// FIXME: add span_label for use of uninitialized variable
err.emit();
self.tcx.cannot_act_on_uninitialized_variable(span,
"use",
&self.describe_lvalue(lvalue),
Origin::Mir)
.span_label(span, format!("use of possibly uninitialized `{}`",
self.describe_lvalue(lvalue)))
.emit();
}

fn report_move_out_while_borrowed(&mut self,
_context: Context,
(lvalue, span): (&Lvalue, Span)) {
let mut err = self.tcx.cannot_move_when_borrowed(
span, &self.describe_lvalue(lvalue), Origin::Mir);
// FIXME 1: add span_label for "borrow of `()` occurs here"
// FIXME 2: add span_label for "move out of `{}` occurs here"
err.emit();
(lvalue, span): (&Lvalue, Span),
borrow: &BorrowData) {
self.tcx.cannot_move_when_borrowed(span,
&self.describe_lvalue(lvalue),
Origin::Mir)
.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,
Expand Down