From b304e60131a081930382a6bf327aa11c6432698c Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 7 Sep 2019 11:21:17 -0400 Subject: [PATCH] Remove Handler::{emit, emit_with_code} --- src/librustc/session/mod.rs | 4 +- src/librustc_codegen_ssa/back/write.rs | 18 +++----- src/librustc_driver/lib.rs | 12 +++--- src/librustc_errors/lib.rs | 59 ++++++++++++-------------- 4 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index af9cb5a0941..afaea540060 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1394,7 +1394,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { Box::new(JsonEmitter::basic(pretty, json_rendered, false)), }; let handler = errors::Handler::with_emitter(true, None, emitter); - handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal); + handler.struct_fatal(msg).emit(); errors::FatalError.raise(); } @@ -1408,7 +1408,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { Box::new(JsonEmitter::basic(pretty, json_rendered, false)), }; let handler = errors::Handler::with_emitter(true, None, emitter); - handler.emit(&MultiSpan::new(), msg, errors::Level::Warning); + handler.struct_warn(msg).emit(); } pub type CompileResult = Result<(), ErrorReported>; diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 38a0818d290..1bba479c1fd 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -27,7 +27,6 @@ use rustc_target::spec::MergeFunctions; use syntax::attr; use syntax::ext::hygiene::ExpnId; -use syntax_pos::MultiSpan; use syntax_pos::symbol::{Symbol, sym}; use jobserver::{Client, Acquired}; @@ -1760,19 +1759,12 @@ pub fn check(&self, sess: &Session, blocking: bool) { match message { Ok(SharedEmitterMessage::Diagnostic(diag)) => { let handler = sess.diagnostic(); - match diag.code { - Some(ref code) => { - handler.emit_with_code(&MultiSpan::new(), - &diag.msg, - code.clone(), - diag.lvl); - } - None => { - handler.emit(&MultiSpan::new(), - &diag.msg, - diag.lvl); - } + let mut d = rustc_errors::Diagnostic::new(diag.lvl, &diag.msg); + if let Some(code) = diag.code { + d.code(code); } + handler.emit_diagnostic(&d); + handler.abort_if_errors_and_should_abort(); } Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => { sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 3a09f459e9c..f99e65b4494 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -66,7 +66,7 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures}; use syntax::parse::{self, PResult}; use syntax::symbol::sym; -use syntax_pos::{DUMMY_SP, MultiSpan, FileName}; +use syntax_pos::{DUMMY_SP, FileName}; pub mod pretty; mod args; @@ -1203,9 +1203,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // a .span_bug or .bug call has already printed what // it wants to print. if !info.payload().is::() { - handler.emit(&MultiSpan::new(), - "unexpected panic", - errors::Level::Bug); + let d = errors::Diagnostic::new(errors::Level::Bug, "unexpected panic"); + handler.emit_diagnostic(&d); + handler.abort_if_errors_and_should_abort(); } let mut xs: Vec> = vec![ @@ -1225,9 +1225,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { } for note in &xs { - handler.emit(&MultiSpan::new(), - note, - errors::Level::Note); + handler.note_without_error(¬e); } // If backtraces are enabled, also print the query stack diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 47ac2e5a667..b74a6035032 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -539,7 +539,8 @@ fn panic_if_treat_err_as_bug(&self) { } pub fn span_fatal>(&self, sp: S, msg: &str) -> FatalError { - self.emit(&sp.into(), msg, Fatal); + self.emit_diagnostic(Diagnostic::new(Fatal, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); FatalError } pub fn span_fatal_with_code>(&self, @@ -547,11 +548,13 @@ pub fn span_fatal_with_code>(&self, msg: &str, code: DiagnosticId) -> FatalError { - self.emit_with_code(&sp.into(), msg, code, Fatal); + self.emit_diagnostic(Diagnostic::new_with_code(Fatal, Some(code), msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); FatalError } pub fn span_err>(&self, sp: S, msg: &str) { - self.emit(&sp.into(), msg, Error); + self.emit_diagnostic(Diagnostic::new(Error, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn mut_span_err>(&self, sp: S, @@ -562,16 +565,20 @@ pub fn mut_span_err>(&self, result } pub fn span_err_with_code>(&self, sp: S, msg: &str, code: DiagnosticId) { - self.emit_with_code(&sp.into(), msg, code, Error); + self.emit_diagnostic(Diagnostic::new_with_code(Error, Some(code), msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn span_warn>(&self, sp: S, msg: &str) { - self.emit(&sp.into(), msg, Warning); + self.emit_diagnostic(Diagnostic::new(Warning, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn span_warn_with_code>(&self, sp: S, msg: &str, code: DiagnosticId) { - self.emit_with_code(&sp.into(), msg, code, Warning); + self.emit_diagnostic(Diagnostic::new_with_code(Warning, Some(code), msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn span_bug>(&self, sp: S, msg: &str) -> ! { - self.emit(&sp.into(), msg, Bug); + self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); panic!(ExplicitBug); } pub fn delay_span_bug>(&self, sp: S, msg: &str) { @@ -590,10 +597,12 @@ fn delay_as_bug(&self, diagnostic: Diagnostic) { self.delayed_span_bugs.borrow_mut().push(diagnostic); } pub fn span_bug_no_panic>(&self, sp: S, msg: &str) { - self.emit(&sp.into(), msg, Bug); + self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn span_note_without_error>(&self, sp: S, msg: &str) { - self.emit(&sp.into(), msg, Note); + self.emit_diagnostic(Diagnostic::new(Note, msg).set_span(sp)); + self.abort_if_errors_and_should_abort(); } pub fn span_note_diag(&self, sp: Span, @@ -701,31 +710,15 @@ pub fn print_error_count(&self, registry: &Registry) { } } - pub fn abort_if_errors(&self) { - if self.has_errors() { + pub fn abort_if_errors_and_should_abort(&self) { + if self.has_errors() && !self.continue_after_error.load(SeqCst) { FatalError.raise(); } } - pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) { - if lvl == Warning && !self.flags.can_emit_warnings { - return; - } - let mut db = DiagnosticBuilder::new(self, lvl, msg); - db.set_span(msp.clone()); - db.emit(); - if !self.continue_after_error.load(SeqCst) { - self.abort_if_errors(); - } - } - pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) { - if lvl == Warning && !self.flags.can_emit_warnings { - return; - } - let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg); - db.set_span(msp.clone()); - db.emit(); - if !self.continue_after_error.load(SeqCst) { - self.abort_if_errors(); + + pub fn abort_if_errors(&self) { + if self.has_errors() { + FatalError.raise(); } } @@ -747,6 +740,10 @@ pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) { return; } + if diagnostic.level == Warning && !self.flags.can_emit_warnings { + return; + } + TRACK_DIAGNOSTICS.with(|track_diagnostics| { track_diagnostics.get()(diagnostic); });