Skip to content

Commit

Permalink
Always print aborting due to n previous error(s) and only print it …
Browse files Browse the repository at this point in the history
…once for multi-threaded code
  • Loading branch information
Zoxc committed Mar 16, 2018
1 parent 3b43dcb commit 910bf84
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
54 changes: 30 additions & 24 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use rustc_resolve as resolve;
use rustc_save_analysis as save;
use rustc_save_analysis::DumpHandler;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::OnDrop;
use rustc::session::{self, config, Session, build_session, CompileResult};
use rustc::session::CompileIncomplete;
use rustc::session::config::{Input, PrintRequest, ErrorOutputType};
Expand Down Expand Up @@ -515,30 +516,35 @@ fn run_compiler_impl<'a>(args: &[String],
target_features::add_configuration(&mut cfg, &sess, &*trans);
sess.parse_sess.config = cfg;

let plugins = sess.opts.debugging_opts.extra_plugins.clone();

let cstore = CStore::new(trans.metadata_loader());

do_or_return!(callbacks.late_callback(&*trans,
&matches,
&sess,
&cstore,
&input,
&odir,
&ofile), Some(sess));

let control = callbacks.build_controller(&sess, &matches);

(driver::compile_input(trans,
&sess,
&cstore,
&input_file_path,
&input,
&odir,
&ofile,
Some(plugins),
&control),
Some(sess))
let result = {
let plugins = sess.opts.debugging_opts.extra_plugins.clone();

let cstore = CStore::new(trans.metadata_loader());

do_or_return!(callbacks.late_callback(&*trans,
&matches,
&sess,
&cstore,
&input,
&odir,
&ofile), Some(sess));

let _sess_abort_error = OnDrop(|| sess.diagnostic().print_error_count());

let control = callbacks.build_controller(&sess, &matches);

driver::compile_input(trans,
&sess,
&cstore,
&input_file_path,
&input,
&odir,
&ofile,
Some(plugins),
&control)
};

(result, Some(sess))
}

// Extract output directory and file from matches.
Expand Down
34 changes: 18 additions & 16 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,15 @@ impl Handler {
pub fn has_errors(&self) -> bool {
self.err_count() > 0
}
pub fn abort_if_errors(&self) {
let s;
match self.err_count() {
0 => {
if let Some(bug) = self.delayed_span_bug.borrow_mut().take() {
DiagnosticBuilder::new_diagnostic(self, bug).emit();
}
return;
}
1 => s = "aborting due to previous error".to_string(),
_ => {
s = format!("aborting due to {} previous errors", self.err_count());
}
}
let err = self.fatal(&s);

pub fn print_error_count(&self) {
let s = match self.err_count() {
0 => return,
1 => "aborting due to previous error".to_string(),
_ => format!("aborting due to {} previous errors", self.err_count())
};

let _ = self.fatal(&s);

let can_show_explain = self.emitter.borrow().should_show_explain();
let are_there_diagnostics = !self.tracked_diagnostic_codes.borrow().is_empty();
Expand Down Expand Up @@ -600,8 +594,16 @@ impl Handler {
}
}
}
}

err.raise();
pub fn abort_if_errors(&self) {
if self.err_count() == 0 {
if let Some(bug) = self.delayed_span_bug.borrow_mut().take() {
DiagnosticBuilder::new_diagnostic(self, bug).emit();
}
return;
}
FatalError.raise();
}
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
if lvl == Warning && !self.flags.can_emit_warnings {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::slice;
use require_c_abi_if_variadic;
use util::common::ErrorReported;
use util::nodemap::FxHashSet;
use errors::FatalError;

use std::iter;
use syntax::{abi, ast};
Expand Down Expand Up @@ -337,7 +338,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
Def::Trait(trait_def_id) => trait_def_id,
Def::TraitAlias(alias_def_id) => alias_def_id,
Def::Err => {
self.tcx().sess.fatal("cannot continue compilation due to previous error");
FatalError.raise();
}
_ => unreachable!(),
}
Expand Down

0 comments on commit 910bf84

Please sign in to comment.