diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-04-20 15:52:52 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-05-02 11:49:24 -0400 |
| commit | 41a652e0948d6cbcffa89a219b37a1e39ae619d4 (patch) | |
| tree | 8f87e6d7dc9ce8378febdb0a6678b3d06ae044be /src/libsyntax/errors | |
| parent | 489a6c95bf747059b28472efc17d39795c6adcad (diff) | |
| download | rust-41a652e0948d6cbcffa89a219b37a1e39ae619d4.tar.gz rust-41a652e0948d6cbcffa89a219b37a1e39ae619d4.zip | |
WIP factor out RudimentaryEmitter
Diffstat (limited to 'src/libsyntax/errors')
| -rw-r--r-- | src/libsyntax/errors/emitter.rs | 47 |
1 files changed, 31 insertions, 16 deletions
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<T: RudimentaryEmitter> 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 { |
