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

+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
@@ -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

+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
}

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

+2
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

+2
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

+2-1
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

+2
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

+2
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

+2-1
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

+2-1
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`.

src/test/ui/feature-gate-fn_must_use-cap-lints-allow.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ error: compilation successful
44
LL | fn main() {} //~ ERROR compilation successful
55
| ^^^^^^^^^^^^
66

7+
error: aborting due to previous error
8+

src/test/ui/feature-gate-fn_must_use.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ error: compilation successful
2020
LL | fn main() {} //~ ERROR compilation successful
2121
| ^^^^^^^^^^^^
2222

23+
error: aborting due to previous error
24+

src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,5 @@ LL | | println!("Hello World");
13161316
LL | | }
13171317
| |_^
13181318

1319+
error: aborting due to previous error
1320+

src/test/ui/feature-gate/issue-43106-gating-of-deprecated.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | | println!("Hello World");
66
LL | | }
77
| |_^
88

9+
error: aborting due to previous error
10+

src/test/ui/impl-trait/universal_wrong_bounds.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ help: possible candidate is found in another module, you can import it into scop
2424
LL | use std::fmt::Debug;
2525
|
2626

27-
error: cannot continue compilation due to previous error
27+
error: aborting due to 3 previous errors
2828

29+
Some errors occurred: E0405, E0425.
30+
For more information about an error, try `rustc --explain E0405`.

src/test/ui/issue-22644.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ error: expected type, found `4`
8989
LL | println!("{}", a: &mut 4); //~ ERROR expected type, found `4`
9090
| ^ expecting a type here because of type ascription
9191

92+
error: aborting due to 9 previous errors
93+

src/test/ui/issue-44406.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ LL | bar(baz: $rest)
1313
LL | foo!(true); //~ ERROR expected type, found keyword
1414
| ^^^^ expecting a type here because of type ascription
1515

16+
error: aborting due to 2 previous errors
17+

src/test/ui/lint-output-format-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ LL | | let _y = bar();
2222
LL | | }
2323
| |_^
2424

25+
error: aborting due to previous error
26+

src/test/ui/loops-reject-duplicate-labels-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ LL | | foo();
7070
LL | | }
7171
| |_^
7272

73+
error: aborting due to previous error
74+

src/test/ui/loops-reject-duplicate-labels.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ LL | | foo();
7373
LL | | }
7474
| |_^
7575

76+
error: aborting due to previous error
77+

src/test/ui/loops-reject-labels-shadowing-lifetimes.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ LL | | foo();
108108
LL | | }
109109
| |_^
110110

111+
error: aborting due to previous error
112+

src/test/ui/loops-reject-lifetime-shadowing-label.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ LL | | foo();
1414
LL | | }
1515
| |_^
1616

17+
error: aborting due to previous error
18+

src/test/ui/macro-context.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ LL | () => ( i ; typeof ); //~ ERROR expected expression, found reserved k
4343
LL | m!();
4444
| ----- in this macro invocation
4545

46+
error: aborting due to 4 previous errors
47+

src/test/ui/macros/macro_path_as_generic_bound.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ error[E0433]: failed to resolve. Use of undeclared type or module `m`
44
LL | foo!(m::m2::A); //~ ERROR failed to resolve
55
| ^ Use of undeclared type or module `m`
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 E0433`.

src/test/ui/macros/trace_faulty_macros.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ LL | my_recursive_macro!();
4545
= note: expanding `my_recursive_macro! { }`
4646
= note: to `my_recursive_macro ! ( ) ;`
4747

48+
error: aborting due to 2 previous errors
49+

src/test/ui/raw_string.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ LL | let x = r##"lol"#;
66
|
77
= note: this raw string should be terminated with `"##`
88

9+
error: aborting due to previous error
10+

src/test/ui/resolve/issue-21221-1.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ help: possible candidate is found in another module, you can import it into scop
4545
LL | use std::ops::Div;
4646
|
4747

48-
error: cannot continue compilation due to previous error
48+
error: aborting due to 4 previous errors
4949

50+
Some errors occurred: E0405, E0412.
51+
For more information about an error, try `rustc --explain E0405`.

src/test/ui/resolve/issue-21221-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ help: possible candidate is found in another module, you can import it into scop
88
LL | use foo::bar::T;
99
|
1010

11-
error: cannot continue compilation due to previous error
11+
error: aborting due to previous error
1212

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

src/test/ui/resolve/issue-21221-3.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ help: possible candidate is found in another module, you can import it into scop
88
LL | use issue_21221_3::outer::OuterTrait;
99
|
1010

11-
error: cannot continue compilation due to previous error
11+
error: aborting due to previous error
1212

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

src/test/ui/resolve/issue-21221-4.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ help: possible candidate is found in another module, you can import it into scop
88
LL | use issue_21221_4::T;
99
|
1010

11-
error: cannot continue compilation due to previous error
11+
error: aborting due to previous error
1212

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

src/test/ui/resolve/issue-3907.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ help: possible better candidate is found in another module, you can import it in
88
LL | use issue_3907::Foo;
99
|
1010

11-
error: cannot continue compilation due to previous error
11+
error: aborting due to previous error
1212

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

src/test/ui/resolve/issue-5035.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ LL | impl K for isize {} //~ ERROR expected trait, found type alias `K`
1313
| did you mean `I`?
1414
| type aliases cannot be used for traits
1515

16-
error: cannot continue compilation due to previous error
16+
error: aborting due to 2 previous errors
1717

18+
Some errors occurred: E0404, E0432.
19+
For more information about an error, try `rustc --explain E0404`.

src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ error[E0404]: expected trait, found type alias `Typedef`
1010
LL | fn g<F:Typedef(isize) -> isize>(x: F) {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used for traits
1212

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

15+
Some errors occurred: E0404, E0405.
16+
For more information about an error, try `rustc --explain E0404`.
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
error: cannot continue compilation due to previous error
2-

src/test/ui/span/issue-24690.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ LL | | println!("{}", theTwo);
3636
LL | | }
3737
| |_^
3838

39+
error: aborting due to previous error
40+

src/test/ui/span/issue-35987.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ help: possible better candidate is found in another module, you can import it in
88
LL | use std::ops::Add;
99
|
1010

11-
error: cannot continue compilation due to previous error
11+
error: aborting due to previous error
1212

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

0 commit comments

Comments
 (0)