clean up BorrowckDiags
- rename it to what it does, buffer diagnostics - remove single-use functions - use derives
This commit is contained in:
parent
fbefa2e267
commit
8c86e52ed7
3 changed files with 13 additions and 23 deletions
|
@ -85,7 +85,8 @@ impl<'infcx> BufferedDiag<'infcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct BorrowckDiagnosticsBuffer<'infcx, 'tcx> {
|
||||
/// This field keeps track of move errors that are to be reported for given move indices.
|
||||
///
|
||||
/// There are situations where many errors can be reported for a single move out (see
|
||||
|
@ -108,19 +109,7 @@ pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
|
|||
buffered_diags: Vec<BufferedDiag<'infcx>>,
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> {
|
||||
pub(crate) fn new() -> Self {
|
||||
BorrowckDiags {
|
||||
buffered_move_errors: BTreeMap::new(),
|
||||
buffered_mut_errors: Default::default(),
|
||||
buffered_diags: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
|
||||
self.buffered_diags.push(BufferedDiag::Error(diag));
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> BorrowckDiagnosticsBuffer<'infcx, 'tcx> {
|
||||
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
|
||||
self.buffered_diags.push(BufferedDiag::NonError(diag));
|
||||
}
|
||||
|
@ -128,7 +117,7 @@ impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> {
|
|||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
|
||||
self.diags.buffer_error(diag);
|
||||
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
|
||||
}
|
||||
|
||||
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
|
||||
|
@ -166,7 +155,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
// 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.buffer_error(diag);
|
||||
self.buffer_error(diag);
|
||||
}
|
||||
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
|
||||
if count > 10 {
|
||||
|
@ -174,7 +163,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
|
||||
}
|
||||
self.diags.buffer_error(diag);
|
||||
self.buffer_error(diag);
|
||||
}
|
||||
|
||||
if !self.diags.buffered_diags.is_empty() {
|
||||
|
|
|
@ -19,7 +19,6 @@ use std::cell::RefCell;
|
|||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
|
||||
use diagnostics::BorrowckDiags;
|
||||
use rustc_abi::FieldIdx;
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
|
@ -51,7 +50,9 @@ use tracing::{debug, instrument};
|
|||
use crate::borrow_set::{BorrowData, BorrowSet};
|
||||
use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions};
|
||||
use crate::dataflow::{BorrowIndex, Borrowck, BorrowckDomain, Borrows};
|
||||
use crate::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName};
|
||||
use crate::diagnostics::{
|
||||
AccessKind, BorrowckDiagnosticsBuffer, IllegalMoveOriginKind, MoveError, RegionName,
|
||||
};
|
||||
use crate::path_utils::*;
|
||||
use crate::place_ext::PlaceExt;
|
||||
use crate::places_conflict::{PlaceConflictBias, places_conflict};
|
||||
|
@ -216,7 +217,7 @@ fn do_mir_borrowck<'tcx>(
|
|||
|
||||
// We also have a `#[rustc_regions]` annotation that causes us to dump
|
||||
// information.
|
||||
let diags = &mut BorrowckDiags::new();
|
||||
let diags = &mut BorrowckDiagnosticsBuffer::default();
|
||||
nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, &opaque_type_values, diags);
|
||||
|
||||
let movable_coroutine =
|
||||
|
@ -565,7 +566,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
|
|||
/// Results of Polonius analysis.
|
||||
polonius_output: Option<Box<PoloniusOutput>>,
|
||||
|
||||
diags: &'a mut BorrowckDiags<'infcx, 'tcx>,
|
||||
diags: &'a mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
|
||||
move_errors: Vec<MoveError<'tcx>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ use tracing::{debug, instrument};
|
|||
|
||||
use crate::borrow_set::BorrowSet;
|
||||
use crate::consumers::ConsumerOptions;
|
||||
use crate::diagnostics::{BorrowckDiags, RegionErrors};
|
||||
use crate::diagnostics::{BorrowckDiagnosticsBuffer, RegionErrors};
|
||||
use crate::polonius::LocalizedOutlivesConstraintSet;
|
||||
use crate::polonius::legacy::{AllFacts, AllFactsExt, LocationTable, PoloniusOutput};
|
||||
use crate::region_infer::RegionInferenceContext;
|
||||
|
@ -298,7 +298,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
|
|||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
|
||||
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||
diags: &mut BorrowckDiags<'infcx, 'tcx>,
|
||||
diags: &mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
|
||||
) {
|
||||
let tcx = infcx.tcx;
|
||||
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue