use syntax::ast::{NodeId, NodeIdAssigner, Name};
use syntax::codemap::Span;
-use syntax::errors;
-use syntax::errors::emitter::{Emitter, BasicEmitter};
+use syntax::errors::{self, DiagnosticBuilder};
+use syntax::errors::emitter::{Emitter, BasicEmitter, EmitterWriter};
+use syntax::errors::json::JsonEmitter;
use syntax::diagnostics;
use syntax::feature_gate;
use syntax::parse;
}
impl Session {
+ pub fn struct_span_warn<'a>(&'a self,
+ sp: Span,
+ msg: &str)
+ -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_span_warn(sp, msg)
+ }
+ pub fn struct_span_warn_with_code<'a>(&'a self,
+ sp: Span,
+ msg: &str,
+ code: &str)
+ -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_span_warn_with_code(sp, msg, code)
+ }
+ pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_warn(msg)
+ }
+ pub fn struct_span_err<'a>(&'a self,
+ sp: Span,
+ msg: &str)
+ -> DiagnosticBuilder<'a> {
+ match split_msg_into_multilines(msg) {
+ Some(ref msg) => self.diagnostic().struct_span_err(sp, msg),
+ None => self.diagnostic().struct_span_err(sp, msg),
+ }
+ }
+ pub fn struct_span_err_with_code<'a>(&'a self,
+ sp: Span,
+ msg: &str,
+ code: &str)
+ -> DiagnosticBuilder<'a> {
+ match split_msg_into_multilines(msg) {
+ Some(ref msg) => self.diagnostic().struct_span_err_with_code(sp, msg, code),
+ None => self.diagnostic().struct_span_err_with_code(sp, msg, code),
+ }
+ }
+ pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_err(msg)
+ }
+ pub fn struct_span_fatal<'a>(&'a self,
+ sp: Span,
+ msg: &str)
+ -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_span_fatal(sp, msg)
+ }
+ pub fn struct_span_fatal_with_code<'a>(&'a self,
+ sp: Span,
+ msg: &str,
+ code: &str)
+ -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
+ }
+ pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
+ self.diagnostic().struct_fatal(msg)
+ }
+
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
panic!(self.diagnostic().span_fatal(sp, msg))
}
}
pub fn span_err(&self, sp: Span, msg: &str) {
match split_msg_into_multilines(msg) {
- Some(msg) => self.diagnostic().span_err(sp, &msg[..]),
+ Some(msg) => self.diagnostic().span_err(sp, &msg),
None => self.diagnostic().span_err(sp, msg)
}
}
- pub fn note_rfc_1214(&self, span: Span) {
- self.span_note(
- span,
- &format!("this warning results from recent bug fixes and clarifications; \
- it will become a HARD ERROR in the next release. \
- See RFC 1214 for details."));
- }
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
match split_msg_into_multilines(msg) {
- Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code),
+ Some(msg) => self.diagnostic().span_err_with_code(sp, &msg, code),
None => self.diagnostic().span_err_with_code(sp, msg, code)
}
}
pub fn abort_if_errors(&self) {
self.diagnostic().abort_if_errors();
}
- pub fn abort_if_new_errors<F>(&self, mut f: F)
- where F: FnMut()
+ pub fn abort_if_new_errors<F, T>(&self, f: F) -> T
+ where F: FnOnce() -> T
{
let count = self.err_count();
- f();
+ let result = f();
if self.err_count() > count {
self.abort_if_errors();
}
+ result
}
pub fn span_warn(&self, sp: Span, msg: &str) {
self.diagnostic().span_warn(sp, msg)
None => self.warn(msg),
}
}
- pub fn span_note(&self, sp: Span, msg: &str) {
- self.diagnostic().span_note(sp, msg)
- }
- pub fn span_end_note(&self, sp: Span, msg: &str) {
- self.diagnostic().span_end_note(sp, msg)
- }
-
- /// Prints out a message with a suggested edit of the code.
- ///
- /// See `errors::RenderSpan::Suggestion` for more information.
- pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
- self.diagnostic().span_suggestion(sp, msg, suggestion)
- }
- pub fn span_help(&self, sp: Span, msg: &str) {
- self.diagnostic().span_help(sp, msg)
- }
- pub fn fileline_note(&self, sp: Span, msg: &str) {
- self.diagnostic().fileline_note(sp, msg)
- }
- pub fn fileline_help(&self, sp: Span, msg: &str) {
- self.diagnostic().fileline_help(sp, msg)
- }
- pub fn note(&self, msg: &str) {
- self.diagnostic().note(msg)
- }
- pub fn help(&self, msg: &str) {
- self.diagnostic().help(msg)
- }
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
match opt_sp {
Some(sp) => self.span_bug(sp, msg),
pub fn bug(&self, msg: &str) -> ! {
self.diagnostic().bug(msg)
}
+ pub fn note_without_error(&self, msg: &str) {
+ self.diagnostic().note_without_error(msg)
+ }
+ pub fn span_note_without_error(&self, sp: Span, msg: &str) {
+ self.diagnostic().span_note_without_error(sp, msg)
+ }
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
self.diagnostic().span_unimpl(sp, msg)
}
let treat_err_as_bug = sopts.treat_err_as_bug;
let codemap = Rc::new(codemap::CodeMap::new());
+ let emitter: Box<Emitter> = match sopts.error_format {
+ config::ErrorOutputType::HumanReadable(color_config) => {
+ Box::new(EmitterWriter::stderr(color_config, Some(registry), codemap.clone()))
+ }
+ config::ErrorOutputType::Json => {
+ Box::new(JsonEmitter::stderr(Some(registry), codemap.clone()))
+ }
+ };
+
let diagnostic_handler =
- errors::Handler::new(sopts.color,
- Some(registry),
- can_print_warnings,
- treat_err_as_bug,
- codemap.clone());
+ errors::Handler::with_emitter(can_print_warnings,
+ treat_err_as_bug,
+ emitter);
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
}
sess
}
-pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
- let mut emitter = BasicEmitter::stderr(color);
+pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
+ let mut emitter: Box<Emitter> = match output {
+ config::ErrorOutputType::HumanReadable(color_config) => {
+ Box::new(BasicEmitter::stderr(color_config))
+ }
+ config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
+ };
emitter.emit(None, msg, None, errors::Level::Fatal);
panic!(errors::FatalError);
}
-pub fn early_warn(color: errors::ColorConfig, msg: &str) {
- let mut emitter = BasicEmitter::stderr(color);
+pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
+ let mut emitter: Box<Emitter> = match output {
+ config::ErrorOutputType::HumanReadable(color_config) => {
+ Box::new(BasicEmitter::stderr(color_config))
+ }
+ config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
+ };
emitter.emit(None, msg, None, errors::Level::Warning);
}