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 Oct 29, 2024
1 parent a9b0909 commit 41c968e
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 @@ -228,14 +228,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);

let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
.into_engine(tcx, body)
Expand Down Expand Up @@ -292,7 +285,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 @@ -580,7 +572,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 @@ -2499,15 +2491,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 41c968e

Please sign in to comment.