Skip to content

Commit

Permalink
Merge pull request rust-lang#3466 from topecongiro/discard-error-to-sink
Browse files Browse the repository at this point in the history
Discard error report in silent_emitter
  • Loading branch information
topecongiro authored Mar 24, 2019
2 parents cc26c5e + 037cf2c commit 9b43441
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::rc::Rc;
use std::time::{Duration, Instant};

use syntax::ast;
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
use syntax::errors::emitter::{ColorConfig, Emitter};
use syntax::errors::{DiagnosticBuilder, Handler};
use syntax::parse::{self, ParseSess};
use syntax::source_map::{FilePathMapping, SourceMap, Span, DUMMY_SP};
Expand Down Expand Up @@ -90,7 +90,7 @@ fn format_project<T: FormatHandler>(
timer = timer.done_parsing();

// Suppress error output if we have to do any further parsing.
let silent_emitter = silent_emitter(source_map);
let silent_emitter = silent_emitter();
parse_session.span_diagnostic = Handler::with_emitter(true, None, silent_emitter);

let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
Expand Down Expand Up @@ -672,18 +672,20 @@ fn parse_crate(
Err(ErrorKind::ParseError)
}

fn silent_emitter(source_map: Rc<SourceMap>) -> Box<EmitterWriter> {
Box::new(EmitterWriter::new(
Box::new(Vec::new()),
Some(source_map),
false,
false,
))
/// Emitter which discards every error.
struct SilentEmitter;

impl Emitter for SilentEmitter {
fn emit(&mut self, _db: &DiagnosticBuilder<'_>) {}
}

fn silent_emitter() -> Box<SilentEmitter> {
Box::new(SilentEmitter {})
}

fn make_parse_sess(source_map: Rc<SourceMap>, config: &Config) -> ParseSess {
let tty_handler = if config.hide_parse_errors() {
let silent_emitter = silent_emitter(source_map.clone());
let silent_emitter = silent_emitter();
Handler::with_emitter(true, None, silent_emitter)
} else {
let supports_color = term::stderr().map_or(false, |term| term.supports_color());
Expand Down

0 comments on commit 9b43441

Please sign in to comment.