Skip to content

Commit 910bf84

Browse files
committed
Always print aborting due to n previous error(s) and only print it once for multi-threaded code
1 parent 3b43dcb commit 910bf84

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

src/librustc_driver/lib.rs

+30-24
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use rustc_resolve as resolve;
6363
use rustc_save_analysis as save;
6464
use rustc_save_analysis::DumpHandler;
6565
use rustc_data_structures::sync::Lrc;
66+
use rustc_data_structures::OnDrop;
6667
use rustc::session::{self, config, Session, build_session, CompileResult};
6768
use rustc::session::CompileIncomplete;
6869
use rustc::session::config::{Input, PrintRequest, ErrorOutputType};
@@ -515,30 +516,35 @@ fn run_compiler_impl<'a>(args: &[String],
515516
target_features::add_configuration(&mut cfg, &sess, &*trans);
516517
sess.parse_sess.config = cfg;
517518

518-
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
519-
520-
let cstore = CStore::new(trans.metadata_loader());
521-
522-
do_or_return!(callbacks.late_callback(&*trans,
523-
&matches,
524-
&sess,
525-
&cstore,
526-
&input,
527-
&odir,
528-
&ofile), Some(sess));
529-
530-
let control = callbacks.build_controller(&sess, &matches);
531-
532-
(driver::compile_input(trans,
533-
&sess,
534-
&cstore,
535-
&input_file_path,
536-
&input,
537-
&odir,
538-
&ofile,
539-
Some(plugins),
540-
&control),
541-
Some(sess))
519+
let result = {
520+
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
521+
522+
let cstore = CStore::new(trans.metadata_loader());
523+
524+
do_or_return!(callbacks.late_callback(&*trans,
525+
&matches,
526+
&sess,
527+
&cstore,
528+
&input,
529+
&odir,
530+
&ofile), Some(sess));
531+
532+
let _sess_abort_error = OnDrop(|| sess.diagnostic().print_error_count());
533+
534+
let control = callbacks.build_controller(&sess, &matches);
535+
536+
driver::compile_input(trans,
537+
&sess,
538+
&cstore,
539+
&input_file_path,
540+
&input,
541+
&odir,
542+
&ofile,
543+
Some(plugins),
544+
&control)
545+
};
546+
547+
(result, Some(sess))
542548
}
543549

544550
// Extract output directory and file from matches.

src/librustc_errors/lib.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,15 @@ impl Handler {
555555
pub fn has_errors(&self) -> bool {
556556
self.err_count() > 0
557557
}
558-
pub fn abort_if_errors(&self) {
559-
let s;
560-
match self.err_count() {
561-
0 => {
562-
if let Some(bug) = self.delayed_span_bug.borrow_mut().take() {
563-
DiagnosticBuilder::new_diagnostic(self, bug).emit();
564-
}
565-
return;
566-
}
567-
1 => s = "aborting due to previous error".to_string(),
568-
_ => {
569-
s = format!("aborting due to {} previous errors", self.err_count());
570-
}
571-
}
572-
let err = self.fatal(&s);
558+
559+
pub fn print_error_count(&self) {
560+
let s = match self.err_count() {
561+
0 => return,
562+
1 => "aborting due to previous error".to_string(),
563+
_ => format!("aborting due to {} previous errors", self.err_count())
564+
};
565+
566+
let _ = self.fatal(&s);
573567

574568
let can_show_explain = self.emitter.borrow().should_show_explain();
575569
let are_there_diagnostics = !self.tracked_diagnostic_codes.borrow().is_empty();
@@ -600,8 +594,16 @@ impl Handler {
600594
}
601595
}
602596
}
597+
}
603598

604-
err.raise();
599+
pub fn abort_if_errors(&self) {
600+
if self.err_count() == 0 {
601+
if let Some(bug) = self.delayed_span_bug.borrow_mut().take() {
602+
DiagnosticBuilder::new_diagnostic(self, bug).emit();
603+
}
604+
return;
605+
}
606+
FatalError.raise();
605607
}
606608
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
607609
if lvl == Warning && !self.flags.can_emit_warnings {

src/librustc_typeck/astconv.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::slice;
2727
use require_c_abi_if_variadic;
2828
use util::common::ErrorReported;
2929
use util::nodemap::FxHashSet;
30+
use errors::FatalError;
3031

3132
use std::iter;
3233
use syntax::{abi, ast};
@@ -337,7 +338,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
337338
Def::Trait(trait_def_id) => trait_def_id,
338339
Def::TraitAlias(alias_def_id) => alias_def_id,
339340
Def::Err => {
340-
self.tcx().sess.fatal("cannot continue compilation due to previous error");
341+
FatalError.raise();
341342
}
342343
_ => unreachable!(),
343344
}

0 commit comments

Comments
 (0)