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};
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)
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;
// 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![
}
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
}
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,
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,
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) {
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,
}
}
- 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();
}
}
return;
}
+ if diagnostic.level == Warning && !self.flags.can_emit_warnings {
+ return;
+ }
+
TRACK_DIAGNOSTICS.with(|track_diagnostics| {
track_diagnostics.get()(diagnostic);
});