Remove Handler::{emit, emit_with_code}

This commit is contained in:
Mark Rousskov 2019-09-07 11:21:17 -04:00
parent 998df0d70b
commit b304e60131
4 changed files with 40 additions and 53 deletions

View File

@ -1394,7 +1394,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
Box::new(JsonEmitter::basic(pretty, json_rendered, false)), Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
}; };
let handler = errors::Handler::with_emitter(true, None, emitter); 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(); errors::FatalError.raise();
} }
@ -1408,7 +1408,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
Box::new(JsonEmitter::basic(pretty, json_rendered, false)), Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
}; };
let handler = errors::Handler::with_emitter(true, None, emitter); 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>; pub type CompileResult = Result<(), ErrorReported>;

View File

@ -27,7 +27,6 @@
use rustc_target::spec::MergeFunctions; use rustc_target::spec::MergeFunctions;
use syntax::attr; use syntax::attr;
use syntax::ext::hygiene::ExpnId; use syntax::ext::hygiene::ExpnId;
use syntax_pos::MultiSpan;
use syntax_pos::symbol::{Symbol, sym}; use syntax_pos::symbol::{Symbol, sym};
use jobserver::{Client, Acquired}; use jobserver::{Client, Acquired};
@ -1760,19 +1759,12 @@ pub fn check(&self, sess: &Session, blocking: bool) {
match message { match message {
Ok(SharedEmitterMessage::Diagnostic(diag)) => { Ok(SharedEmitterMessage::Diagnostic(diag)) => {
let handler = sess.diagnostic(); let handler = sess.diagnostic();
match diag.code { let mut d = rustc_errors::Diagnostic::new(diag.lvl, &diag.msg);
Some(ref code) => { if let Some(code) = diag.code {
handler.emit_with_code(&MultiSpan::new(), d.code(code);
&diag.msg,
code.clone(),
diag.lvl);
}
None => {
handler.emit(&MultiSpan::new(),
&diag.msg,
diag.lvl);
}
} }
handler.emit_diagnostic(&d);
handler.abort_if_errors_and_should_abort();
} }
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => { Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg) sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg)

View File

@ -66,7 +66,7 @@
use syntax::feature_gate::{GatedCfg, UnstableFeatures}; use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult}; use syntax::parse::{self, PResult};
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, MultiSpan, FileName}; use syntax_pos::{DUMMY_SP, FileName};
pub mod pretty; pub mod pretty;
mod args; 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 // a .span_bug or .bug call has already printed what
// it wants to print. // it wants to print.
if !info.payload().is::<errors::ExplicitBug>() { if !info.payload().is::<errors::ExplicitBug>() {
handler.emit(&MultiSpan::new(), let d = errors::Diagnostic::new(errors::Level::Bug, "unexpected panic");
"unexpected panic", handler.emit_diagnostic(&d);
errors::Level::Bug); handler.abort_if_errors_and_should_abort();
} }
let mut xs: Vec<Cow<'static, str>> = vec![ let mut xs: Vec<Cow<'static, str>> = vec![
@ -1225,9 +1225,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
} }
for note in &xs { for note in &xs {
handler.emit(&MultiSpan::new(), handler.note_without_error(&note);
note,
errors::Level::Note);
} }
// If backtraces are enabled, also print the query stack // If backtraces are enabled, also print the query stack

View File

@ -539,7 +539,8 @@ fn panic_if_treat_err_as_bug(&self) {
} }
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError { pub fn span_fatal<S: Into<MultiSpan>>(&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 FatalError
} }
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self, pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
@ -547,11 +548,13 @@ pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
msg: &str, msg: &str,
code: DiagnosticId) code: DiagnosticId)
-> FatalError { -> 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 FatalError
} }
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { pub fn span_err<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, pub fn mut_span_err<S: Into<MultiSpan>>(&self,
sp: S, sp: S,
@ -562,16 +565,20 @@ pub fn mut_span_err<S: Into<MultiSpan>>(&self,
result result
} }
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) { pub fn span_err_with_code<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { pub fn span_warn<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) { pub fn span_warn_with_code<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! { pub fn span_bug<S: Into<MultiSpan>>(&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); panic!(ExplicitBug);
} }
pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
@ -590,10 +597,12 @@ fn delay_as_bug(&self, diagnostic: Diagnostic) {
self.delayed_span_bugs.borrow_mut().push(diagnostic); self.delayed_span_bugs.borrow_mut().push(diagnostic);
} }
pub fn span_bug_no_panic<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { pub fn span_bug_no_panic<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { pub fn span_note_without_error<S: Into<MultiSpan>>(&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, pub fn span_note_diag(&self,
sp: Span, sp: Span,
@ -701,31 +710,15 @@ pub fn print_error_count(&self, registry: &Registry) {
} }
} }
pub fn abort_if_errors(&self) { pub fn abort_if_errors_and_should_abort(&self) {
if self.has_errors() { if self.has_errors() && !self.continue_after_error.load(SeqCst) {
FatalError.raise(); FatalError.raise();
} }
} }
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
if lvl == Warning && !self.flags.can_emit_warnings { pub fn abort_if_errors(&self) {
return; if self.has_errors() {
} FatalError.raise();
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();
} }
} }
@ -747,6 +740,10 @@ pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
return; return;
} }
if diagnostic.level == Warning && !self.flags.can_emit_warnings {
return;
}
TRACK_DIAGNOSTICS.with(|track_diagnostics| { TRACK_DIAGNOSTICS.with(|track_diagnostics| {
track_diagnostics.get()(diagnostic); track_diagnostics.get()(diagnostic);
}); });