Skip to content

Commit 0b586b4

Browse files
Take Diagnostic in Handler::emit_diagnostic
1 parent cdd8055 commit 0b586b4

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18551855
struct NullEmitter;
18561856

18571857
impl errors::emitter::Emitter for NullEmitter {
1858-
fn emit_diagnostic(&mut self, _: &errors::DiagnosticBuilder<'_>) {}
1858+
fn emit_diagnostic(&mut self, _: &errors::Diagnostic) {}
18591859
}
18601860

18611861
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.

src/librustc_errors/diagnostic_builder.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,9 @@ impl<'a> DerefMut for DiagnosticBuilder<'a> {
9999
}
100100

101101
impl<'a> DiagnosticBuilder<'a> {
102-
pub fn handler(&self) -> &'a Handler{
103-
self.0.handler
104-
}
105-
106102
/// Emit the diagnostic.
107103
pub fn emit(&mut self) {
108-
if self.cancelled() {
109-
return;
110-
}
111-
112-
self.0.handler.emit_db(&self);
104+
self.0.handler.emit_diagnostic(&self);
113105
self.cancel();
114106
}
115107

src/librustc_errors/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl Handler {
589589
}
590590
fn delay_as_bug(&self, diagnostic: Diagnostic) {
591591
if self.flags.report_delayed_bugs {
592-
DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit();
592+
self.emit_diagnostic(&diagnostic);
593593
}
594594
self.delayed_span_bugs.borrow_mut().push(diagnostic);
595595
}
@@ -747,8 +747,10 @@ impl Handler {
747747
db.cancel();
748748
}
749749

750-
fn emit_db(&self, db: &DiagnosticBuilder<'_>) {
751-
let diagnostic = &**db;
750+
fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
751+
if diagnostic.cancelled() {
752+
return;
753+
}
752754

753755
TRACK_DIAGNOSTICS.with(|track_diagnostics| {
754756
track_diagnostics.get()(diagnostic);
@@ -768,12 +770,12 @@ impl Handler {
768770
// Only emit the diagnostic if we haven't already emitted an equivalent
769771
// one:
770772
if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
771-
self.emitter.borrow_mut().emit_diagnostic(db);
772-
if db.is_error() {
773+
self.emitter.borrow_mut().emit_diagnostic(diagnostic);
774+
if diagnostic.is_error() {
773775
self.deduplicated_err_count.fetch_add(1, SeqCst);
774776
}
775777
}
776-
if db.is_error() {
778+
if diagnostic.is_error() {
777779
self.bump_err_count();
778780
}
779781
}

0 commit comments

Comments
 (0)