Skip to content

Commit 9eebe77

Browse files
committed
Have add_explanation_to_diagnostic also take Mir as parameter.
This is preparation for allowing the `BorrowExplanation` carry things like `mir::Location` or `mir::Local` and still be able to generate usable diagnostic text.
1 parent 8532c18 commit 9eebe77

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
262262
move_spans.var_span_label(&mut err, "move occurs due to use in closure");
263263

264264
self.explain_why_borrow_contains_point(context, borrow, None)
265-
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
265+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
266266
err.buffer(&mut self.errors_buffer);
267267
}
268268

@@ -299,7 +299,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
299299
});
300300

301301
self.explain_why_borrow_contains_point(context, borrow, None)
302-
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
302+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
303303
err.buffer(&mut self.errors_buffer);
304304
}
305305

@@ -483,7 +483,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
483483
}
484484

485485
self.explain_why_borrow_contains_point(context, issued_borrow, None)
486-
.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, first_borrow_desc.to_string());
486+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, first_borrow_desc.to_string());
487487

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

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

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

652-
explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
652+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
653653
}
654654

655655
err
@@ -709,7 +709,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
709709
_ => {}
710710
}
711711

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

714714
err.buffer(&mut self.errors_buffer);
715715
}
@@ -776,7 +776,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
776776
}
777777
_ => {}
778778
}
779-
explanation.add_explanation_to_diagnostic(self.infcx.tcx, &mut err, String::new());
779+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, String::new());
780780

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

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

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

918918
err.buffer(&mut self.errors_buffer);
919919
}

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use borrow_check::error_reporting::UseSpans;
1313
use borrow_check::nll::region_infer::Cause;
1414
use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
1515
use rustc::ty::{Region, TyCtxt};
16-
use rustc::mir::{FakeReadCause, Location, Operand, Place, StatementKind, TerminatorKind};
16+
use rustc::mir::{FakeReadCause, Location, Mir, Operand, Place, StatementKind, TerminatorKind};
1717
use rustc_errors::DiagnosticBuilder;
1818
use syntax_pos::Span;
1919
use syntax_pos::symbol::Symbol;
@@ -40,6 +40,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
4040
pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx>(
4141
&self,
4242
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
43+
_mir: &Mir<'tcx>,
4344
err: &mut DiagnosticBuilder<'_>,
4445
borrow_desc: String,
4546
) {

0 commit comments

Comments
 (0)