Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ pub(crate) struct BorrowckDiagnosticsBuffer<'diag, 'tcx> {

buffered_mut_errors: FxIndexMap<Span, (Diag<'diag>, usize)>,

/// Buffer of diagnostics to be reported.
buffered_diags: Vec<Diag<'diag>>,
/// Buffer of diagnostics to be reported. Each one is paired with a span for sorting purposes;
/// by default it's the primary span.
buffered_diags: Vec<(Span, Diag<'diag>)>,
}

impl<'diag, 'tcx> BorrowckDiagnosticsBuffer<'diag, 'tcx> {
pub(crate) fn buffer_error(&mut self, diag: Diag<'diag>) {
self.buffered_diags.push(diag);
let sort_span = diag.span.primary_span().unwrap_or(DUMMY_SP);
self.buffered_diags.push((sort_span, diag));
}

pub(crate) fn buffer_error_with_sort_span(&mut self, diag: Diag<'diag>, sort_span: Span) {
self.buffered_diags.push((sort_span, diag));
}

pub(crate) fn emit_errors(&mut self) {
Expand All @@ -117,8 +123,8 @@ impl<'diag, 'tcx> BorrowckDiagnosticsBuffer<'diag, 'tcx> {
}

if !self.buffered_diags.is_empty() {
self.buffered_diags.sort_by_key(|diag| diag.sort_span);
for diag in self.buffered_diags.drain(..) {
self.buffered_diags.sort_by_key(|(sort_span, _)| *sort_span);
for (_, diag) in self.buffered_diags.drain(..) {
diag.emit();
}
}
Expand All @@ -130,6 +136,10 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
self.diags_buffer.buffer_error(diag.with_dcx(self.dcx()));
}

pub(crate) fn buffer_error_with_sort_span(&mut self, diag: Diag<'_>, sort_span: Span) {
self.diags_buffer.buffer_error_with_sort_span(diag.with_dcx(self.dcx()), sort_span);
}

pub(crate) fn buffer_move_error(
&mut self,
move_out_indices: Vec<MoveOutIndex>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ impl OutlivesSuggestionBuilder {

// We want this message to appear after other messages on the mir def.
let mir_span = mbcx.body.span;
diag.sort_span = mir_span.shrink_to_hi();

// Buffer the diagnostic
mbcx.buffer_error(diag);
mbcx.buffer_error_with_sort_span(diag, mir_span.shrink_to_hi());
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,6 @@ pub struct CguMessage;
// - `span`: it doesn't impl `Send`.
// - `suggestions`: it doesn't impl `Send`, and isn't used for codegen
// diagnostics.
// - `sort_span`: it doesn't impl `Send`.
// - `is_lint`: lints aren't relevant during codegen.
// - `emitted_at`: not used for codegen diagnostics.
struct Diagnostic {
Expand Down Expand Up @@ -1993,7 +1992,6 @@ impl Emitter for SharedEmitter {
// the cut-down local `DiagInner`.
assert!(!diag.span.has_span_labels());
assert_eq!(diag.suggestions, Suggestions::Enabled(vec![]));
assert_eq!(diag.sort_span, rustc_span::DUMMY_SP);
assert_eq!(diag.is_lint, None);
// No sensible check for `diag.emitted_at`.

Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_error_messages::{DiagArgMap, DiagArgName, IntoDiagArg};
use rustc_hashes::Hash128;
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_macros::{Decodable, Encodable};
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol};
use rustc_span::{Span, Spanned, Symbol};
use tracing::debug;

use crate::{
Expand Down Expand Up @@ -195,14 +195,7 @@ pub struct DiagInner {
pub children: Vec<Subdiag>,
pub suggestions: Suggestions,
pub args: DiagArgMap,

/// This is not used for highlighting or rendering any error message. Rather, it can be used
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
/// `span` if there is one. Otherwise, it is `DUMMY_SP`.
pub sort_span: Span,

pub is_lint: Option<IsLint>,

pub long_ty_path: Option<PathBuf>,
/// With `-Ztrack_diagnostics` enabled,
/// we print where in rustc this error was emitted.
Expand All @@ -226,7 +219,6 @@ impl DiagInner {
children: vec![],
suggestions: Suggestions::Enabled(vec![]),
args: Default::default(),
sort_span: DUMMY_SP,
is_lint: None,
long_ty_path: None,
emitted_at: DiagLocation::caller(),
Expand Down Expand Up @@ -320,7 +312,6 @@ impl DiagInner {
children,
suggestions,
args,
sort_span: _, // ignore
is_lint,
long_ty_path: _, // ignore
emitted_at: _, // ignore
Expand Down Expand Up @@ -1088,9 +1079,6 @@ impl<'a> Diag<'a> {
/// Add a span.
pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
self.span = sp.into();
if let Some(span) = self.span.primary_span() {
self.sort_span = span;
}
self
} }

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4751,7 +4751,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
} else {
err.children.append(&mut parent_err.children);
}
err.sort_span = parent_err.sort_span;
err.is_lint = parent_err.is_lint.clone();

// merge the parent_err's suggestions with the typo (err's) suggestions
Expand Down
Loading