Stop using DiagnosticBuilder::buffer in BorrowckErrors.

But we can't easily switch from `Vec<Diagnostic>` to
`Vec<DiagnosticBuilder<G>>` because there's a mix of errors and warnings
which result in different `G` types. So we must make
`DiagnosticBuilder::into_diagnostic` public, but that's ok, and it will
get more use in subsequent commits.
This commit is contained in:
Nicholas Nethercote 2024-01-11 11:22:10 +11:00
parent 29c601aa0b
commit fbe68bc40c
2 changed files with 11 additions and 10 deletions

View File

@ -2399,10 +2399,10 @@ mod error {
/// and we want only the best of those errors. /// and we want only the best of those errors.
/// ///
/// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the /// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the
/// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of the /// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of
/// `Place` of the previous most diagnostic. This happens instead of buffering the error. Once /// the `Place` of the previous most diagnostic. This happens instead of buffering the
/// all move errors have been reported, any diagnostics in this map are added to the buffer /// error. Once all move errors have been reported, any diagnostics in this map are added
/// to be emitted. /// to the buffer to be emitted.
/// ///
/// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary /// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
/// when errors in the map are being re-added to the error buffer so that errors with the /// when errors in the map are being re-added to the error buffer so that errors with the
@ -2410,7 +2410,8 @@ mod error {
buffered_move_errors: buffered_move_errors:
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>, BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx>, usize)>, buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx>, usize)>,
/// Diagnostics to be reported buffer. /// Buffer of diagnostics to be reported. Uses `Diagnostic` rather than `DiagnosticBuilder`
/// because it has a mixture of error diagnostics and non-error diagnostics.
buffered: Vec<Diagnostic>, buffered: Vec<Diagnostic>,
/// Set to Some if we emit an error during borrowck /// Set to Some if we emit an error during borrowck
tainted_by_errors: Option<ErrorGuaranteed>, tainted_by_errors: Option<ErrorGuaranteed>,
@ -2434,11 +2435,11 @@ mod error {
"diagnostic buffered but not emitted", "diagnostic buffered but not emitted",
)) ))
} }
t.buffer(&mut self.buffered); self.buffered.push(t.into_diagnostic());
} }
pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) { pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
t.buffer(&mut self.buffered); self.buffered.push(t.into_diagnostic());
} }
pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) { pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) {
@ -2486,13 +2487,13 @@ mod error {
// Buffer any move errors that we collected and de-duplicated. // Buffer any move errors that we collected and de-duplicated.
for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) { for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) {
// We have already set tainted for this error, so just buffer it. // We have already set tainted for this error, so just buffer it.
diag.buffer(&mut self.errors.buffered); self.errors.buffered.push(diag.into_diagnostic());
} }
for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) { for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) {
if count > 10 { if count > 10 {
diag.note(format!("...and {} other attempted mutable borrows", count - 10)); diag.note(format!("...and {} other attempted mutable borrows", count - 10));
} }
diag.buffer(&mut self.errors.buffered); self.errors.buffered.push(diag.into_diagnostic());
} }
if !self.errors.buffered.is_empty() { if !self.errors.buffered.is_empty() {

View File

@ -260,7 +260,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
} }
/// Converts the builder to a `Diagnostic` for later emission. /// Converts the builder to a `Diagnostic` for later emission.
fn into_diagnostic(mut self) -> Diagnostic { pub fn into_diagnostic(mut self) -> Diagnostic {
self.take_diag() self.take_diag()
} }