Skip to content

Commit b4fca11

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 83d4285 commit b4fca11

File tree

1 file changed

+5
-13
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+5
-13
lines changed

compiler/rustc_borrowck/src/lib.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn do_mir_borrowck<'tcx>(
162162
}
163163
}
164164

165-
let mut diags = diags::BorrowckDiags::new();
165+
let diags = &mut diags::BorrowckDiags::new();
166166

167167
// Gather the upvars of a closure, if any.
168168
if let Some(e) = input_body.tainted_by_errors {
@@ -228,14 +228,7 @@ fn do_mir_borrowck<'tcx>(
228228

229229
// We also have a `#[rustc_regions]` annotation that causes us to dump
230230
// information.
231-
nll::dump_annotation(
232-
&infcx,
233-
body,
234-
&regioncx,
235-
&opt_closure_req,
236-
&opaque_type_values,
237-
&mut diags,
238-
);
231+
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
239232

240233
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
241234
.into_engine(tcx, body)
@@ -292,7 +285,6 @@ fn do_mir_borrowck<'tcx>(
292285
};
293286
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
294287
promoted_mbcx.report_move_errors();
295-
diags = promoted_mbcx.diags;
296288

297289
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
298290
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
@@ -580,7 +572,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
580572
/// Results of Polonius analysis.
581573
polonius_output: Option<Box<PoloniusOutput>>,
582574

583-
diags: diags::BorrowckDiags<'infcx, 'tcx>,
575+
diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>,
584576
move_errors: Vec<MoveError<'tcx>>,
585577
}
586578

@@ -2499,15 +2491,15 @@ mod diags {
24992491
// Buffer any move errors that we collected and de-duplicated.
25002492
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
25012493
// We have already set tainted for this error, so just buffer it.
2502-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2494+
self.diags.buffer_error(diag);
25032495
}
25042496
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
25052497
if count > 10 {
25062498
#[allow(rustc::diagnostic_outside_of_impl)]
25072499
#[allow(rustc::untranslatable_diagnostic)]
25082500
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
25092501
}
2510-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2502+
self.diags.buffer_error(diag);
25112503
}
25122504

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

0 commit comments

Comments
 (0)