Skip to content

Commit 14ff4b3

Browse files
committed
Remove {DiagCtxt,DiagCtxtInner}::emit_diagnostic_without_consuming.
They are no longer used, because `{DiagCtxt,DiagCtxtInner}::emit_diagnostic` are used everywhere instead. This also means `track_diagnostic` can become consuming.
1 parent f645542 commit 14ff4b3

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

compiler/rustc_errors/src/lib.rs

+7-23
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ pub enum StashKey {
509509
Cycle,
510510
}
511511

512-
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
513-
(*f)(d)
512+
fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
513+
(*f)(diag)
514514
}
515515

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

519519
#[derive(Copy, Clone, Default)]
@@ -1079,17 +1079,8 @@ impl DiagCtxt {
10791079
self.inner.borrow_mut().emitter.emit_diagnostic(&db);
10801080
}
10811081

1082-
pub fn emit_diagnostic(&self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
1083-
self.emit_diagnostic_without_consuming(&mut diagnostic)
1084-
}
1085-
1086-
// It's unfortunate this exists. `emit_diagnostic` is preferred, because it
1087-
// consumes the diagnostic, thus ensuring it is emitted just once.
1088-
pub(crate) fn emit_diagnostic_without_consuming(
1089-
&self,
1090-
diagnostic: &mut Diagnostic,
1091-
) -> Option<ErrorGuaranteed> {
1092-
self.inner.borrow_mut().emit_diagnostic_without_consuming(diagnostic)
1082+
pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
1083+
self.inner.borrow_mut().emit_diagnostic(diagnostic)
10931084
}
10941085

10951086
#[track_caller]
@@ -1278,13 +1269,6 @@ impl DiagCtxtInner {
12781269
}
12791270

12801271
fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
1281-
self.emit_diagnostic_without_consuming(&mut diagnostic)
1282-
}
1283-
1284-
fn emit_diagnostic_without_consuming(
1285-
&mut self,
1286-
diagnostic: &mut Diagnostic,
1287-
) -> Option<ErrorGuaranteed> {
12881272
if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() {
12891273
diagnostic.level = Bug;
12901274
}
@@ -1340,7 +1324,7 @@ impl DiagCtxtInner {
13401324
}
13411325

13421326
let mut guaranteed = None;
1343-
(*TRACK_DIAGNOSTICS)(diagnostic, &mut |diagnostic| {
1327+
(*TRACK_DIAGNOSTICS)(diagnostic, &mut |mut diagnostic| {
13441328
if let Some(ref code) = diagnostic.code {
13451329
self.emitted_diagnostic_codes.insert(code.clone());
13461330
}
@@ -1376,7 +1360,7 @@ impl DiagCtxtInner {
13761360
);
13771361
}
13781362

1379-
self.emitter.emit_diagnostic(diagnostic);
1363+
self.emitter.emit_diagnostic(&diagnostic);
13801364
if diagnostic.is_error() {
13811365
self.deduplicated_err_count += 1;
13821366
} else if let Warning(_) = diagnostic.level {

compiler/rustc_interface/src/callbacks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
2929
/// This is a callback from `rustc_errors` as it cannot access the implicit state
3030
/// in `rustc_middle` otherwise. It is used when diagnostic messages are
3131
/// emitted and stores them in the current query, if there is one.
32-
fn track_diagnostic(diagnostic: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
32+
fn track_diagnostic(diagnostic: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
3333
tls::with_context_opt(|icx| {
3434
if let Some(icx) = icx {
3535
if let Some(diagnostics) = icx.diagnostics {

0 commit comments

Comments
 (0)