Reset the error count of parser from the previous file

This commit is contained in:
topecongiro 2017-06-10 14:16:12 +09:00
parent c879d5ebd7
commit 762639e7fd

View file

@ -427,9 +427,10 @@ impl fmt::Display for FormatReport {
// Formatting which depends on the AST. // Formatting which depends on the AST.
fn format_ast<F>(krate: &ast::Crate, fn format_ast<F>(krate: &ast::Crate,
parse_session: &ParseSess, mut parse_session: &mut ParseSess,
main_file: &Path, main_file: &Path,
config: &Config, config: &Config,
codemap: &Rc<CodeMap>,
mut after_file: F) mut after_file: F)
-> Result<(FileMap, bool), io::Error> -> Result<(FileMap, bool), io::Error>
where F: FnMut(&str, &mut StringBuffer) -> Result<bool, io::Error> where F: FnMut(&str, &mut StringBuffer) -> Result<bool, io::Error>
@ -449,6 +450,7 @@ fn format_ast<F>(krate: &ast::Crate,
if config.verbose() { if config.verbose() {
println!("Formatting {}", path); println!("Formatting {}", path);
} }
{
let mut visitor = FmtVisitor::from_codemap(parse_session, config); let mut visitor = FmtVisitor::from_codemap(parse_session, config);
visitor.format_separate_mod(module); visitor.format_separate_mod(module);
@ -456,6 +458,12 @@ fn format_ast<F>(krate: &ast::Crate,
result.push((path.to_owned(), visitor.buffer)); result.push((path.to_owned(), visitor.buffer));
} }
// Reset the error count.
if parse_session.span_diagnostic.has_errors() {
parse_session.span_diagnostic =
Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
}
}
Ok((result, has_diff)) Ok((result, has_diff))
} }
@ -612,9 +620,10 @@ pub fn format_input<T: Write>(input: Input,
match format_ast( match format_ast(
&krate, &krate,
&parse_session, &mut parse_session,
&main_file, &main_file,
config, config,
&codemap,
|file_name, file| { |file_name, file| {
// For some reason, the codemap does not include terminating // For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad. // newlines so we must add one on for each file. This is sad.