Skip to content

Commit 8c86e52

Browse files
committed
clean up BorrowckDiags
- rename it to what it does, buffer diagnostics - remove single-use functions - use derives
1 parent fbefa2e commit 8c86e52

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ impl<'infcx> BufferedDiag<'infcx> {
8585
}
8686
}
8787

88-
pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
88+
#[derive(Default)]
89+
pub(crate) struct BorrowckDiagnosticsBuffer<'infcx, 'tcx> {
8990
/// This field keeps track of move errors that are to be reported for given move indices.
9091
///
9192
/// There are situations where many errors can be reported for a single move out (see
@@ -108,27 +109,15 @@ pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
108109
buffered_diags: Vec<BufferedDiag<'infcx>>,
109110
}
110111

111-
impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> {
112-
pub(crate) fn new() -> Self {
113-
BorrowckDiags {
114-
buffered_move_errors: BTreeMap::new(),
115-
buffered_mut_errors: Default::default(),
116-
buffered_diags: Default::default(),
117-
}
118-
}
119-
120-
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
121-
self.buffered_diags.push(BufferedDiag::Error(diag));
122-
}
123-
112+
impl<'infcx, 'tcx> BorrowckDiagnosticsBuffer<'infcx, 'tcx> {
124113
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
125114
self.buffered_diags.push(BufferedDiag::NonError(diag));
126115
}
127116
}
128117

129118
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
130119
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
131-
self.diags.buffer_error(diag);
120+
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
132121
}
133122

134123
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
@@ -166,15 +155,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
166155
// Buffer any move errors that we collected and de-duplicated.
167156
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
168157
// We have already set tainted for this error, so just buffer it.
169-
self.diags.buffer_error(diag);
158+
self.buffer_error(diag);
170159
}
171160
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
172161
if count > 10 {
173162
#[allow(rustc::diagnostic_outside_of_impl)]
174163
#[allow(rustc::untranslatable_diagnostic)]
175164
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
176165
}
177-
self.diags.buffer_error(diag);
166+
self.buffer_error(diag);
178167
}
179168

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

compiler/rustc_borrowck/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::cell::RefCell;
1919
use std::marker::PhantomData;
2020
use std::ops::Deref;
2121

22-
use diagnostics::BorrowckDiags;
2322
use rustc_abi::FieldIdx;
2423
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2524
use rustc_data_structures::graph::dominators::Dominators;
@@ -51,7 +50,9 @@ use tracing::{debug, instrument};
5150
use crate::borrow_set::{BorrowData, BorrowSet};
5251
use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions};
5352
use crate::dataflow::{BorrowIndex, Borrowck, BorrowckDomain, Borrows};
54-
use crate::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName};
53+
use crate::diagnostics::{
54+
AccessKind, BorrowckDiagnosticsBuffer, IllegalMoveOriginKind, MoveError, RegionName,
55+
};
5556
use crate::path_utils::*;
5657
use crate::place_ext::PlaceExt;
5758
use crate::places_conflict::{PlaceConflictBias, places_conflict};
@@ -216,7 +217,7 @@ fn do_mir_borrowck<'tcx>(
216217

217218
// We also have a `#[rustc_regions]` annotation that causes us to dump
218219
// information.
219-
let diags = &mut BorrowckDiags::new();
220+
let diags = &mut BorrowckDiagnosticsBuffer::default();
220221
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
221222

222223
let movable_coroutine =
@@ -565,7 +566,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
565566
/// Results of Polonius analysis.
566567
polonius_output: Option<Box<PoloniusOutput>>,
567568

568-
diags: &'a mut BorrowckDiags<'infcx, 'tcx>,
569+
diags: &'a mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
569570
move_errors: Vec<MoveError<'tcx>>,
570571
}
571572

compiler/rustc_borrowck/src/nll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{debug, instrument};
2626

2727
use crate::borrow_set::BorrowSet;
2828
use crate::consumers::ConsumerOptions;
29-
use crate::diagnostics::{BorrowckDiags, RegionErrors};
29+
use crate::diagnostics::{BorrowckDiagnosticsBuffer, RegionErrors};
3030
use crate::polonius::LocalizedOutlivesConstraintSet;
3131
use crate::polonius::legacy::{AllFacts, AllFactsExt, LocationTable, PoloniusOutput};
3232
use crate::region_infer::RegionInferenceContext;
@@ -298,7 +298,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
298298
regioncx: &RegionInferenceContext<'tcx>,
299299
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
300300
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
301-
diags: &mut BorrowckDiags<'infcx, 'tcx>,
301+
diags: &mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
302302
) {
303303
let tcx = infcx.tcx;
304304
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());

0 commit comments

Comments
 (0)