Skip to content

Commit f3ad954

Browse files
committed
BorrowckDiags tweaks.
- Store a mut ref to a `BorrowckDiags` in `MirBorrowckCtxt` instead of owning it, to save having to pass ownership in and out of `promoted_mbcx`. - Use `buffer_error` in a couple of suitable places.
1 parent de77c74 commit f3ad954

File tree

1 file changed

+6
-7
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+6
-7
lines changed

compiler/rustc_borrowck/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,10 @@ fn do_mir_borrowck<'tcx>(
279279
&[], // upvars
280280
IndexVec::from_elem(None, &promoted_body.local_decls), // local_names
281281
None, // polonius_output
282-
diags,
282+
&mut diags,
283283
);
284284
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
285285
promoted_mbcx.report_move_errors();
286-
diags = promoted_mbcx.diags;
287286

288287
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
289288
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
@@ -311,7 +310,7 @@ fn do_mir_borrowck<'tcx>(
311310
tcx.closure_captures(def), // upvars
312311
local_names,
313312
polonius_output,
314-
diags,
313+
&mut diags,
315314
);
316315

317316
// Compute and report region errors, if any.
@@ -562,7 +561,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
562561
/// Results of Polonius analysis.
563562
polonius_output: Option<Box<PoloniusOutput>>,
564563

565-
diags: diags::BorrowckDiags<'infcx, 'tcx>,
564+
diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>,
566565
move_errors: Vec<MoveError<'tcx>>,
567566
}
568567

@@ -580,7 +579,7 @@ impl<'a, 'infcx, 'tcx> MirBorrowckCtxt<'a, 'infcx, 'tcx> {
580579
upvars: &'tcx [&'tcx ty::CapturedPlace<'tcx>],
581580
local_names: IndexVec<Local, Option<Symbol>>,
582581
polonius_output: Option<Box<PoloniusOutput>>,
583-
diags: diags::BorrowckDiags<'infcx, 'tcx>,
582+
diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>,
584583
) -> Self {
585584
MirBorrowckCtxt {
586585
infcx,
@@ -2524,15 +2523,15 @@ mod diags {
25242523
// Buffer any move errors that we collected and de-duplicated.
25252524
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
25262525
// We have already set tainted for this error, so just buffer it.
2527-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2526+
self.diags.buffer_error(diag);
25282527
}
25292528
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
25302529
if count > 10 {
25312530
#[allow(rustc::diagnostic_outside_of_impl)]
25322531
#[allow(rustc::untranslatable_diagnostic)]
25332532
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
25342533
}
2535-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2534+
self.diags.buffer_error(diag);
25362535
}
25372536

25382537
if !self.diags.buffered_diags.is_empty() {

0 commit comments

Comments
 (0)