about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-10-25 19:47:40 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-04 17:36:25 +1100
commite0e7a432db38ac26355e7c60219c27720b9ec42f (patch)
treee62fcb1d731f965a0af9dbf4869263a1b6dca787
parentce2f0b4ce9bb34ca22251317ce66c71c1a2df26a (diff)
downloadrust-e0e7a432db38ac26355e7c60219c27720b9ec42f.tar.gz
rust-e0e7a432db38ac26355e7c60219c27720b9ec42f.zip
`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.
-rw-r--r--compiler/rustc_borrowck/src/lib.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index 0d1edd4d383..657e6e0907c 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -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 {
@@ -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
@@ -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>,
@@ -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>>,
 }
 
@@ -2506,7 +2498,7 @@ 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 {
@@ -2514,7 +2506,7 @@ mod diags {
                     #[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() {