Skip to content

Commit

Permalink
BorrowckDiags tweaks.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
nnethercote committed Nov 4, 2024
1 parent ce2f0b4 commit e0e7a43
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn do_mir_borrowck<'tcx>(
}
}

let mut diags = diags::BorrowckDiags::new();
let diags = &mut diags::BorrowckDiags::new();

// Gather the upvars of a closure, if any.
if let Some(e) = input_body.tainted_by_errors {
Expand Down Expand Up @@ -227,14 +227,7 @@ fn do_mir_borrowck<'tcx>(

// We also have a `#[rustc_regions]` annotation that causes us to dump
// information.
nll::dump_annotation(
&infcx,
body,
&regioncx,
&opt_closure_req,
&opaque_type_values,
&mut diags,
);
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);

// The various `flow_*` structures can be large. We drop `flow_inits` here
// so it doesn't overlap with the others below. This reduces peak memory
Expand Down Expand Up @@ -299,7 +292,6 @@ fn do_mir_borrowck<'tcx>(
};
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
promoted_mbcx.report_move_errors();
diags = promoted_mbcx.diags;

struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
Expand Down Expand Up @@ -587,7 +579,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
/// Results of Polonius analysis.
polonius_output: Option<Box<PoloniusOutput>>,

diags: diags::BorrowckDiags<'infcx, 'tcx>,
diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>,
move_errors: Vec<MoveError<'tcx>>,
}

Expand Down Expand Up @@ -2506,15 +2498,15 @@ mod diags {
// Buffer any move errors that we collected and de-duplicated.
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
// We have already set tainted for this error, so just buffer it.
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
self.diags.buffer_error(diag);
}
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
if count > 10 {
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
}
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
self.diags.buffer_error(diag);
}

if !self.diags.buffered_diags.is_empty() {
Expand Down

0 comments on commit e0e7a43

Please sign in to comment.