Skip to content

Commit

Permalink
Have add_explanation_to_diagnostic also take Mir as parameter.
Browse files Browse the repository at this point in the history
This is preparation for allowing the `BorrowExplanation` carry things
like `mir::Location` or `mir::Local` and still be able to generate
usable diagnostic text.
  • Loading branch information
pnkfelix committed Oct 5, 2018
1 parent 8532c18 commit 9eebe77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/librustc_mir/borrow_check/error_reporting.rs
Expand Up @@ -262,7 +262,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
move_spans.var_span_label(&mut err, "move occurs due to use in closure");

self.explain_why_borrow_contains_point(context, borrow, None)
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
err.buffer(&mut self.errors_buffer);
}

Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
});

self.explain_why_borrow_contains_point(context, borrow, None)
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
err.buffer(&mut self.errors_buffer);
}

Expand Down Expand Up @@ -483,7 +483,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}

self.explain_why_borrow_contains_point(context, issued_borrow, None)
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, first_borrow_desc.to_string());
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, first_borrow_desc.to_string());

err.buffer(&mut self.errors_buffer);
}
Expand Down Expand Up @@ -638,7 +638,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

if let BorrowExplanation::MustBeValidFor(..) = explanation {
} else {
explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
}
} else {
err.span_label(borrow_span, "borrowed value does not live long enough");
Expand All @@ -649,7 +649,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

borrow_spans.args_span_label(&mut err, "value captured here");

explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
}

err
Expand Down Expand Up @@ -709,7 +709,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
_ => {}
}

explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());

err.buffer(&mut self.errors_buffer);
}
Expand Down Expand Up @@ -776,7 +776,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}
_ => {}
}
explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());

borrow_spans.args_span_label(&mut err, "value captured here");

Expand Down Expand Up @@ -913,7 +913,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
loan_spans.var_span_label(&mut err, "borrow occurs due to use in closure");

self.explain_why_borrow_contains_point(context, loan, None)
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());

err.buffer(&mut self.errors_buffer);
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Expand Up @@ -13,7 +13,7 @@ use borrow_check::error_reporting::UseSpans;
use borrow_check::nll::region_infer::Cause;
use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
use rustc::ty::{Region, TyCtxt};
use rustc::mir::{FakeReadCause, Location, Operand, Place, StatementKind, TerminatorKind};
use rustc::mir::{FakeReadCause, Location, Mir, Operand, Place, StatementKind, TerminatorKind};
use rustc_errors::DiagnosticBuilder;
use syntax_pos::Span;
use syntax_pos::symbol::Symbol;
Expand All @@ -40,6 +40,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx>(
&self,
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
_mir: &Mir<'tcx>,
err: &mut DiagnosticBuilder<'_>,
borrow_desc: String,
) {
Expand Down

0 comments on commit 9eebe77

Please sign in to comment.