Skip to content

Commit

Permalink
Remove CoreEmitter and focus on Emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed Jul 14, 2016
1 parent a6e7239 commit a019c2c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 68 deletions.
19 changes: 8 additions & 11 deletions src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use syntax::ast;
use syntax::abi::Abi;
use syntax::codemap::CodeMap;
use errors;
use errors::emitter::{CoreEmitter, Emitter};
use errors::{Level, RenderSpan};
use errors::emitter::Emitter;
use errors::{Level, RenderSpan, DiagnosticBuilder};
use syntax::parse::token;
use syntax::feature_gate::UnstableFeatures;
use syntax_pos::DUMMY_SP;
Expand Down Expand Up @@ -76,15 +76,12 @@ fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) {
}
}

impl CoreEmitter for ExpectErrorEmitter {
fn emit_message(&mut self,
_sp: &RenderSpan,
msg: &str,
_: Option<&str>,
lvl: Level,
_is_header: bool,
_show_snippet: bool) {
remove_message(self, msg, lvl);
impl Emitter for ExpectErrorEmitter {
fn emit(&mut self, db: &DiagnosticBuilder) {
remove_message(self, db.message, lvl);
for child in &db.children {
remove_message(self, &child.message, child.level);
}
}
}

Expand Down
79 changes: 36 additions & 43 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,29 @@ use std::io;
use std::rc::Rc;
use term;

/// Emitter trait for emitting errors. Do not implement this directly:
/// implement `CoreEmitter` instead.
/// Emitter trait for emitting errors.
pub trait Emitter {
/// Emit a structured diagnostic.
fn emit(&mut self, db: &DiagnosticBuilder);
}

pub trait CoreEmitter {
fn emit_message(&mut self,
rsp: &RenderSpan,
msg: &str,
code: Option<&str>,
lvl: Level,
is_header: bool,
show_snippet: bool);
}

impl<T: CoreEmitter> Emitter for T {
impl Emitter for EmitterWriter {
fn emit(&mut self, db: &DiagnosticBuilder) {
let old_school = check_old_skool();
let db_span = FullSpan(db.span.clone());
self.emit_message(&FullSpan(db.span.clone()),
&db.message,
db.code.as_ref().map(|s| &**s),
db.level,
true,
true);
for child in &db.children {
let render_span = child.render_span
.clone()
.unwrap_or_else(
|| FullSpan(child.span.clone()));

if !old_school {
self.emit_message(&render_span,
&child.message,
None,
child.level,
false,
true);
} else {
if check_old_skool() {
let db_span = FullSpan(db.span.clone());

for child in &db.children {
let render_span = child.render_span
.clone()
.unwrap_or_else(
|| FullSpan(child.span.clone()));
let (render_span, show_snippet) = match render_span.span().primary_span() {
None => (db_span.clone(), false),
_ => (render_span, true)
Expand All @@ -77,6 +59,19 @@ impl<T: CoreEmitter> Emitter for T {
false,
show_snippet);
}
} else {
for child in &db.children {
let render_span = child.render_span
.clone()
.unwrap_or_else(
|| FullSpan(child.span.clone()));
self.emit_message(&render_span,
&child.message,
None,
child.level,
false,
true);
}
}
}
}
Expand Down Expand Up @@ -114,21 +109,6 @@ pub struct EmitterWriter {
format_mode: FormatMode
}

impl CoreEmitter for EmitterWriter {
fn emit_message(&mut self,
rsp: &RenderSpan,
msg: &str,
code: Option<&str>,
lvl: Level,
is_header: bool,
show_snippet: bool) {
match self.emit_message_(rsp, msg, code, lvl, is_header, show_snippet) {
Ok(()) => { }
Err(e) => panic!("failed to emit error: {}", e)
}
}
}

/// Do not use this for messages that end in `\n` – use `println_maybe_styled` instead. See
/// `EmitterWriter::print_maybe_styled` for details.
macro_rules! print_maybe_styled {
Expand Down Expand Up @@ -177,6 +157,19 @@ impl EmitterWriter {
format_mode: format_mode.clone() }
}

fn emit_message(&mut self,
rsp: &RenderSpan,
msg: &str,
code: Option<&str>,
lvl: Level,
is_header: bool,
show_snippet: bool) {
match self.emit_message_(rsp, msg, code, lvl, is_header, show_snippet) {
Ok(()) => { }
Err(e) => panic!("failed to emit error: {}", e)
}
}

fn emit_message_(&mut self,
rsp: &RenderSpan,
msg: &str,
Expand Down
28 changes: 14 additions & 14 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use llvm::SMDiagnosticRef;
use {CrateTranslation, ModuleTranslation};
use util::common::time;
use util::common::path2cstr;
use errors::{self, Handler, Level, RenderSpan};
use errors::emitter::CoreEmitter;
use errors::{self, Handler, Level, DiagnosticBuilder};
use errors::emitter::Emitter;
use syntax_pos::MultiSpan;

use std::collections::HashMap;
Expand Down Expand Up @@ -100,23 +100,23 @@ impl SharedEmitter {
}
}

impl CoreEmitter for SharedEmitter {
fn emit_message(&mut self,
_rsp: &RenderSpan,
msg: &str,
code: Option<&str>,
lvl: Level,
_is_header: bool,
_show_snippet: bool) {
impl Emitter for SharedEmitter {
fn emit(&mut self, db: &DiagnosticBuilder) {
self.buffer.lock().unwrap().push(Diagnostic {
msg: msg.to_string(),
code: code.map(|s| s.to_string()),
lvl: lvl,
msg: db.message.to_string(),
code: db.code.clone(),
lvl: db.level,
});
for child in &db.children {
self.buffer.lock().unwrap().push(Diagnostic {
msg: child.message.to_string(),
code: None,
lvl: child.level,
});
}
}
}


// On android, we by default compile for armv7 processors. This enables
// things like double word CAS instructions (rather than emulating them)
// which are *far* more efficient. This is obviously undesirable in some
Expand Down

0 comments on commit a019c2c

Please sign in to comment.