Skip to content

Commit 504ab34

Browse files
committed
Replaced String with &str in API for add_explanation_to_diagnostic.
1 parent 9eebe77 commit 504ab34

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
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, self.mir, &mut err, String::new());
265+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, String::new());
302+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, first_borrow_desc.to_string());
486+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, first_borrow_desc);
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, self.mir, &mut err, String::new());
641+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, String::new());
652+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, String::new());
712+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, String::new());
779+
explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
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, self.mir, &mut err, String::new());
916+
.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
917917

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ impl<'tcx> BorrowExplanation<'tcx> {
4242
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
4343
_mir: &Mir<'tcx>,
4444
err: &mut DiagnosticBuilder<'_>,
45-
borrow_desc: String,
45+
borrow_desc: &str,
4646
) {
4747
match *self {
4848
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span) => {
49-
let message = borrow_desc + match later_use_kind {
49+
let message = match later_use_kind {
5050
LaterUseKind::ClosureCapture => "borrow later captured here by closure",
5151
LaterUseKind::Call => "borrow later used by call",
5252
LaterUseKind::FakeLetRead => "borrow later stored here",
5353
LaterUseKind::Other => "borrow later used here",
5454
};
55-
err.span_label(var_or_use_span, message);
55+
err.span_label(var_or_use_span, format!("{}{}", borrow_desc, message));
5656
},
5757
BorrowExplanation::UsedLaterInLoop(later_use_kind, var_or_use_span) => {
58-
let message = borrow_desc + match later_use_kind {
58+
let message = match later_use_kind {
5959
LaterUseKind::ClosureCapture => {
6060
"borrow captured here by closure, in later iteration of loop"
6161
},
6262
LaterUseKind::Call => "borrow used by call, in later iteration of loop",
6363
LaterUseKind::FakeLetRead => "borrow later stored here",
6464
LaterUseKind::Other => "borrow used here, in later iteration of loop",
6565
};
66-
err.span_label(var_or_use_span, message);
66+
err.span_label(var_or_use_span, format!("{}{}", borrow_desc, message));
6767
},
6868
BorrowExplanation::UsedLaterWhenDropped(span, local_name, should_note_order) => {
6969
err.span_label(
@@ -85,7 +85,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
8585
BorrowExplanation::MustBeValidFor(region) => {
8686
tcx.note_and_explain_free_region(
8787
err,
88-
&(borrow_desc + "borrowed value must be valid for "),
88+
&format!("{}{}", borrow_desc, "borrowed value must be valid for "),
8989
region,
9090
"...",
9191
);

0 commit comments

Comments
 (0)