Remove Handler::{emit, emit_with_code}
This commit is contained in:
parent
998df0d70b
commit
b304e60131
@ -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>;
|
||||
|
@ -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)
|
||||
|
@ -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::<errors::ExplicitBug>() {
|
||||
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<Cow<'static, str>> = 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
|
||||
|
@ -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 {
|
||||
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<S: Into<MultiSpan>>(&self,
|
||||
@ -547,11 +548,13 @@ pub fn span_fatal_with_code<S: Into<MultiSpan>>(&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<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,
|
||||
sp: S,
|
||||
@ -562,16 +565,20 @@ pub fn mut_span_err<S: Into<MultiSpan>>(&self,
|
||||
result
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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) -> ! {
|
||||
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<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);
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user