Skip to content

Commit

Permalink
Remove {DiagCtxt,DiagCtxtInner}::emit_diagnostic_without_consuming.
Browse files Browse the repository at this point in the history
They are no longer used, because
`{DiagCtxt,DiagCtxtInner}::emit_diagnostic` are used everywhere instead.

This also means `track_diagnostic` can become consuming.
  • Loading branch information
nnethercote committed Jan 8, 2024
1 parent 2d91c6d commit db09eb2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
30 changes: 7 additions & 23 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ pub enum StashKey {
Cycle,
}

fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
(*f)(d)
fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
(*f)(diag)
}

pub static TRACK_DIAGNOSTICS: AtomicRef<fn(&mut Diagnostic, &mut dyn FnMut(&mut Diagnostic))> =
pub static TRACK_DIAGNOSTICS: AtomicRef<fn(Diagnostic, &mut dyn FnMut(Diagnostic))> =
AtomicRef::new(&(default_track_diagnostic as _));

#[derive(Copy, Clone, Default)]
Expand Down Expand Up @@ -1074,17 +1074,8 @@ impl DiagCtxt {
self.inner.borrow_mut().emitter.emit_diagnostic(&db);
}

pub fn emit_diagnostic(&self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
self.emit_diagnostic_without_consuming(&mut diagnostic)
}

// It's unfortunate this exists. `emit_diagnostic` is preferred, because it
// consumes the diagnostic, thus ensuring it is emitted just once.
pub(crate) fn emit_diagnostic_without_consuming(
&self,
diagnostic: &mut Diagnostic,
) -> Option<ErrorGuaranteed> {
self.inner.borrow_mut().emit_diagnostic_without_consuming(diagnostic)
pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
self.inner.borrow_mut().emit_diagnostic(diagnostic)
}

#[track_caller]
Expand Down Expand Up @@ -1273,13 +1264,6 @@ impl DiagCtxtInner {
}

fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
self.emit_diagnostic_without_consuming(&mut diagnostic)
}

fn emit_diagnostic_without_consuming(
&mut self,
diagnostic: &mut Diagnostic,
) -> Option<ErrorGuaranteed> {
if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() {
diagnostic.level = Bug;
}
Expand Down Expand Up @@ -1335,7 +1319,7 @@ impl DiagCtxtInner {
}

let mut guaranteed = None;
(*TRACK_DIAGNOSTICS)(diagnostic, &mut |diagnostic| {
(*TRACK_DIAGNOSTICS)(diagnostic, &mut |mut diagnostic| {
if let Some(ref code) = diagnostic.code {
self.emitted_diagnostic_codes.insert(code.clone());
}
Expand Down Expand Up @@ -1371,7 +1355,7 @@ impl DiagCtxtInner {
);
}

self.emitter.emit_diagnostic(diagnostic);
self.emitter.emit_diagnostic(&diagnostic);
if diagnostic.is_error() {
self.deduplicated_err_count += 1;
} else if let Warning(_) = diagnostic.level {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
/// This is a callback from `rustc_errors` as it cannot access the implicit state
/// in `rustc_middle` otherwise. It is used when diagnostic messages are
/// emitted and stores them in the current query, if there is one.
fn track_diagnostic(diagnostic: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
fn track_diagnostic(diagnostic: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
tls::with_context_opt(|icx| {
if let Some(icx) = icx {
if let Some(diagnostics) = icx.diagnostics {
Expand Down

0 comments on commit db09eb2

Please sign in to comment.