diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 50fd0392762..ffd8c261b60 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -19,9 +19,9 @@ use llvm::SMDiagnosticRef; use {CrateTranslation, ModuleTranslation}; use util::common::time; use util::common::path2cstr; -use syntax::codemap::{self, MultiSpan}; +use syntax::codemap::MultiSpan; use syntax::errors::{self, Handler, Level}; -use syntax::errors::emitter::Emitter; +use syntax::errors::emitter::RudimentaryEmitter; use std::collections::HashMap; use std::ffi::{CStr, CString}; @@ -100,24 +100,17 @@ impl SharedEmitter { } } -impl Emitter for SharedEmitter { - fn emit(&mut self, - sp: &codemap::MultiSpan, - msg: &str, - code: Option<&str>, - lvl: Level) { - assert!(sp.primary_span().is_none(), "SharedEmitter doesn't support spans"); - +impl RudimentaryEmitter for SharedEmitter { + fn emit_rudimentary(&mut self, + msg: &str, + code: Option<&str>, + lvl: Level) { self.buffer.lock().unwrap().push(Diagnostic { msg: msg.to_string(), code: code.map(|s| s.to_string()), lvl: lvl, }); } - - fn emit_struct(&mut self, _db: &errors::DiagnosticBuilder) { - bug!("SharedEmitter doesn't support emit_struct"); - } } diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index e963a5f794c..f851937d82b 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -25,12 +25,38 @@ use std::rc::Rc; use term; pub trait Emitter { + /// Emit a standalone diagnostic message. fn emit(&mut self, span: &MultiSpan, msg: &str, code: Option<&str>, lvl: Level); /// Emit a structured diagnostic. fn emit_struct(&mut self, db: &DiagnosticBuilder); } +/// A core trait that can only handle very simple messages: those +/// without spans or any real structure. Used only in specific contexts. +pub trait RudimentaryEmitter { + fn emit_rudimentary(&mut self, msg: &str, code: Option<&str>, lvl: Level); +} + +impl Emitter for T { + fn emit(&mut self, + msp: &MultiSpan, + msg: &str, + code: Option<&str>, + lvl: Level) { + assert!(msp.primary_span().is_none(), "Rudimenatry emitters can't handle spans"); + self.emit_rudimentary(msg, code, lvl); + } + + fn emit_struct(&mut self, db: &DiagnosticBuilder) { + self.emit(&db.span, &db.message, db.code.as_ref().map(|s| &**s), db.level); + for child in &db.children { + assert!(child.render_span.is_none(), "Rudimentary emitters can't handle render spans"); + self.emit(&child.span, &child.message, None, child.level); + } + } +} + /// maximum number of lines we will print for each error; arbitrary. pub const MAX_HIGHLIGHT_LINES: usize = 6; @@ -57,26 +83,15 @@ pub struct BasicEmitter { dst: Destination, } -impl Emitter for BasicEmitter { - fn emit(&mut self, - msp: &MultiSpan, - msg: &str, - code: Option<&str>, - lvl: Level) { - assert!(msp.primary_span().is_none(), "BasicEmitter can't handle spans"); - +impl RudimentaryEmitter for BasicEmitter { + fn emit_rudimentary(&mut self, + msg: &str, + code: Option<&str>, + lvl: Level) { if let Err(e) = print_diagnostic(&mut self.dst, "", lvl, msg, code) { panic!("failed to print diagnostics: {:?}", e); } } - - fn emit_struct(&mut self, db: &DiagnosticBuilder) { - self.emit(&db.span, &db.message, db.code.as_ref().map(|s| &**s), db.level); - for child in &db.children { - assert!(child.render_span.is_none(), "BasicEmitter can't handle spans"); - self.emit(&child.span, &child.message, None, child.level); - } - } } impl BasicEmitter {