1
Fork 0

Take Diagnostic in Handler::emit_diagnostic

This commit is contained in:
Mark Rousskov 2019-09-07 10:03:15 -04:00
parent cdd805506e
commit 0b586b436d
3 changed files with 10 additions and 16 deletions

View file

@ -1855,7 +1855,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
struct NullEmitter; struct NullEmitter;
impl errors::emitter::Emitter for NullEmitter { impl errors::emitter::Emitter for NullEmitter {
fn emit_diagnostic(&mut self, _: &errors::DiagnosticBuilder<'_>) {} fn emit_diagnostic(&mut self, _: &errors::Diagnostic) {}
} }
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`. // Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.

View file

@ -99,17 +99,9 @@ impl<'a> DerefMut for DiagnosticBuilder<'a> {
} }
impl<'a> DiagnosticBuilder<'a> { impl<'a> DiagnosticBuilder<'a> {
pub fn handler(&self) -> &'a Handler{
self.0.handler
}
/// Emit the diagnostic. /// Emit the diagnostic.
pub fn emit(&mut self) { pub fn emit(&mut self) {
if self.cancelled() { self.0.handler.emit_diagnostic(&self);
return;
}
self.0.handler.emit_db(&self);
self.cancel(); self.cancel();
} }

View file

@ -589,7 +589,7 @@ impl Handler {
} }
fn delay_as_bug(&self, diagnostic: Diagnostic) { fn delay_as_bug(&self, diagnostic: Diagnostic) {
if self.flags.report_delayed_bugs { if self.flags.report_delayed_bugs {
DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit(); self.emit_diagnostic(&diagnostic);
} }
self.delayed_span_bugs.borrow_mut().push(diagnostic); self.delayed_span_bugs.borrow_mut().push(diagnostic);
} }
@ -747,8 +747,10 @@ impl Handler {
db.cancel(); db.cancel();
} }
fn emit_db(&self, db: &DiagnosticBuilder<'_>) { fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
let diagnostic = &**db; if diagnostic.cancelled() {
return;
}
TRACK_DIAGNOSTICS.with(|track_diagnostics| { TRACK_DIAGNOSTICS.with(|track_diagnostics| {
track_diagnostics.get()(diagnostic); track_diagnostics.get()(diagnostic);
@ -768,12 +770,12 @@ impl Handler {
// Only emit the diagnostic if we haven't already emitted an equivalent // Only emit the diagnostic if we haven't already emitted an equivalent
// one: // one:
if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) { if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
self.emitter.borrow_mut().emit_diagnostic(db); self.emitter.borrow_mut().emit_diagnostic(diagnostic);
if db.is_error() { if diagnostic.is_error() {
self.deduplicated_err_count.fetch_add(1, SeqCst); self.deduplicated_err_count.fetch_add(1, SeqCst);
} }
} }
if db.is_error() { if diagnostic.is_error() {
self.bump_err_count(); self.bump_err_count();
} }
} }