Skip to content

Commit 0acfcb8

Browse files
committed
Rollup merge of rust-lang#49046 - Zoxc:error-summary, r=michaelwoerister
Always print `aborting due to n previous error(s)`
2 parents 175595a + b1d872b commit 0acfcb8

36 files changed

+118
-56
lines changed

src/librustc_driver/lib.rs

Lines changed: 30 additions & 24 deletions
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

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

577571
let can_show_explain = self.emitter.borrow().should_show_explain();
578572
let are_there_diagnostics = !self.tracked_diagnostic_codes.borrow().is_empty();
@@ -603,8 +597,16 @@ impl Handler {
603597
}
604598
}
605599
}
600+
}
606601

607-
err.raise();
602+
pub fn abort_if_errors(&self) {
603+
if self.err_count() == 0 {
604+
if let Some(bug) = self.delayed_span_bug.borrow_mut().take() {
605+
DiagnosticBuilder::new_diagnostic(self, bug).emit();
606+
}
607+
return;
608+
}
609+
FatalError.raise();
608610
}
609611
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
610612
if lvl == Warning && !self.flags.can_emit_warnings {

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 1 deletion
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
}

src/test/ui-fulldeps/custom-derive/issue-36935.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | #[derive(Foo, Bar)] //~ ERROR proc-macro derive panicked
66
|
77
= help: message: lolnope
88

9+
error: aborting due to previous error
10+

src/test/ui-fulldeps/proc-macro/load-panic.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | #[derive(A)]
66
|
77
= help: message: nope!
88

9+
error: aborting due to previous error
10+

src/test/ui/codemap_tests/two_files.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ error[E0404]: expected trait, found type alias `Bar`
44
LL | impl Bar for Baz { } //~ ERROR expected trait, found type alias
55
| ^^^ type aliases cannot be used for traits
66

7-
error: cannot continue compilation due to previous error
7+
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0404`.

src/test/ui/cross-file-errors/main.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ LL | _
99
LL | underscore!();
1010
| -------------- in this macro invocation
1111

12+
error: aborting due to previous error
13+

src/test/ui/did_you_mean/recursion_limit_macro.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ LL | recurse!(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9);
99
|
1010
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate
1111

12+
error: aborting due to previous error
13+

src/test/ui/error-codes/E0404.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ error[E0404]: expected trait, found struct `Foo`
1010
LL | fn baz<T: Foo>(_: T) {} //~ ERROR E0404
1111
| ^^^ not a trait
1212

13-
error: cannot continue compilation due to previous error
13+
error: aborting due to 2 previous errors
1414

15+
For more information about this error, try `rustc --explain E0404`.

src/test/ui/error-codes/E0405.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ error[E0405]: cannot find trait `SomeTrait` in this scope
44
LL | impl SomeTrait for Foo {} //~ ERROR E0405
55
| ^^^^^^^^^ not found in this scope
66

7-
error: cannot continue compilation due to previous error
7+
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)