Skip to content

Commit 95a3215

Browse files
committed
Count all errors for track_errors
1 parent 30b6c59 commit 95a3215

File tree

8 files changed

+77
-29
lines changed

8 files changed

+77
-29
lines changed

src/librustc/infer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub struct InferCtxt<'a, 'tcx> {
171171
/// Track how many errors were reported when this infcx is created.
172172
/// If the number of errors increases, that's also a sign (line
173173
/// `tained_by_errors`) to avoid reporting certain kinds of errors.
174+
// FIXME(matthewjasper) Merge into `tainted_by_errors_flag`
174175
err_count_on_creation: usize,
175176

176177
/// This flag is true while there is an active snapshot.

src/librustc_errors/lib.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ pub use diagnostic_builder::DiagnosticBuilder;
307307
pub struct Handler {
308308
pub flags: HandlerFlags,
309309

310+
/// The number of errors that have been emitted, including duplicates.
311+
///
312+
/// This is not necessarily the count that's reported to the user once
313+
/// compilation ends.
310314
err_count: AtomicUsize,
315+
deduplicated_err_count: AtomicUsize,
311316
emitter: Lock<Box<dyn Emitter + sync::Send>>,
312317
continue_after_error: AtomicBool,
313318
delayed_span_bugs: Lock<Vec<Diagnostic>>,
@@ -407,6 +412,7 @@ impl Handler {
407412
Handler {
408413
flags,
409414
err_count: AtomicUsize::new(0),
415+
deduplicated_err_count: AtomicUsize::new(0),
410416
emitter: Lock::new(e),
411417
continue_after_error: AtomicBool::new(true),
412418
delayed_span_bugs: Lock::new(Vec::new()),
@@ -428,6 +434,7 @@ impl Handler {
428434
pub fn reset_err_count(&self) {
429435
// actually frees the underlying memory (which `clear` would not do)
430436
*self.emitted_diagnostics.borrow_mut() = Default::default();
437+
self.deduplicated_err_count.store(0, SeqCst);
431438
self.err_count.store(0, SeqCst);
432439
}
433440

@@ -660,10 +667,10 @@ impl Handler {
660667
}
661668

662669
pub fn print_error_count(&self, registry: &Registry) {
663-
let s = match self.err_count() {
670+
let s = match self.deduplicated_err_count.load(SeqCst) {
664671
0 => return,
665672
1 => "aborting due to previous error".to_string(),
666-
_ => format!("aborting due to {} previous errors", self.err_count())
673+
count => format!("aborting due to {} previous errors", count)
667674
};
668675
if self.treat_err_as_bug() {
669676
return;
@@ -769,9 +776,12 @@ impl Handler {
769776
if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
770777
self.emitter.borrow_mut().emit_diagnostic(db);
771778
if db.is_error() {
772-
self.bump_err_count();
779+
self.deduplicated_err_count.fetch_add(1, SeqCst);
773780
}
774781
}
782+
if db.is_error() {
783+
self.bump_err_count();
784+
}
775785
}
776786

777787
pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) {

src/librustc_mir/const_eval.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
1515
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1616
use rustc::ty::subst::Subst;
1717
use rustc::traits::Reveal;
18-
use rustc::util::common::ErrorReported;
1918
use rustc_data_structures::fx::FxHashMap;
2019

2120
use syntax::source_map::{Span, DUMMY_SP};
@@ -655,19 +654,12 @@ pub fn const_eval_raw_provider<'tcx>(
655654
if tcx.is_static(def_id) {
656655
// Ensure that if the above error was either `TooGeneric` or `Reported`
657656
// an error must be reported.
658-
let reported_err = tcx.sess.track_errors(|| {
659-
err.report_as_error(ecx.tcx,
660-
"could not evaluate static initializer")
661-
});
662-
match reported_err {
663-
Ok(v) => {
664-
tcx.sess.delay_span_bug(err.span,
665-
&format!("static eval failure did not emit an error: {:#?}",
666-
v));
667-
v
668-
},
669-
Err(ErrorReported) => ErrorHandled::Reported,
670-
}
657+
let v = err.report_as_error(ecx.tcx, "could not evaluate static initializer");
658+
tcx.sess.delay_span_bug(
659+
err.span,
660+
&format!("static eval failure did not emit an error: {:#?}", v)
661+
);
662+
v
671663
} else if def_id.is_local() {
672664
// constant defined in this crate, we can figure out a lint level!
673665
match tcx.def_kind(def_id) {

src/librustc_save_analysis/span_utils.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ use rustc::session::Session;
22

33
use crate::generated_code;
44

5-
use std::cell::Cell;
6-
75
use syntax::parse::lexer::{self, StringReader};
86
use syntax::parse::token::{self, TokenKind};
97
use syntax_pos::*;
108

119
#[derive(Clone)]
1210
pub struct SpanUtils<'a> {
1311
pub sess: &'a Session,
14-
// FIXME given that we clone SpanUtils all over the place, this err_count is
15-
// probably useless and any logic relying on it is bogus.
16-
pub err_count: Cell<isize>,
1712
}
1813

1914
impl<'a> SpanUtils<'a> {
2015
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
2116
SpanUtils {
2217
sess,
23-
err_count: Cell::new(0),
2418
}
2519
}
2620

src/librustc_typeck/check/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ pub struct FnCtxt<'a, 'tcx> {
527527
/// checking this function. On exit, if we find that *more* errors
528528
/// have been reported, we will skip regionck and other work that
529529
/// expects the types within the function to be consistent.
530+
// FIXME(matthewjasper) This should not exist, and it's not correct
531+
// if type checking is run in parallel.
530532
err_count_on_creation: usize,
531533

532534
ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>,
@@ -696,11 +698,9 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
696698
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
697699
}
698700

699-
pub fn check_wf_new<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> {
700-
tcx.sess.track_errors(|| {
701-
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
702-
tcx.hir().krate().par_visit_all_item_likes(&mut visit);
703-
})
701+
pub fn check_wf_new<'tcx>(tcx: TyCtxt<'tcx>) {
702+
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
703+
tcx.hir().krate().par_visit_all_item_likes(&mut visit);
704704
}
705705

706706
fn check_mod_item_types<'tcx>(tcx: TyCtxt<'tcx>, module_def_id: DefId) {

src/librustc_typeck/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> {
321321

322322
// this ensures that later parts of type checking can assume that items
323323
// have valid types and not error
324+
// FIXME(matthewjasper) We shouldn't need to do this.
324325
tcx.sess.track_errors(|| {
325326
time(tcx.sess, "type collecting", || {
326327
for &module in tcx.hir().krate().modules.keys() {
@@ -353,7 +354,9 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> {
353354
})?;
354355
}
355356

356-
time(tcx.sess, "wf checking", || check::check_wf_new(tcx))?;
357+
tcx.sess.track_errors(|| {
358+
time(tcx.sess, "wf checking", || check::check_wf_new(tcx));
359+
})?;
357360

358361
time(tcx.sess, "item-types checking", || {
359362
for &module in tcx.hir().krate().modules.keys() {
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Test that we mark enum discriminant values as having errors, even when the
2+
// diagnostic is deduplicated.
3+
4+
struct F;
5+
struct T;
6+
7+
impl F {
8+
const V: i32 = 0;
9+
}
10+
11+
impl T {
12+
const V: i32 = 0;
13+
}
14+
15+
macro_rules! mac {
16+
($( $v: ident = $s: ident,)*) => {
17+
enum E {
18+
$( $v = $s::V, )*
19+
//~^ ERROR mismatched types
20+
}
21+
}
22+
}
23+
24+
mac! {
25+
A = F,
26+
B = T,
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/enum-discr-type-err.rs:18:21
3+
|
4+
LL | $( $v = $s::V, )*
5+
| ^^^^^ expected isize, found i32
6+
...
7+
LL | / mac! {
8+
LL | | A = F,
9+
LL | | B = T,
10+
LL | | }
11+
| |_- in this macro invocation
12+
help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
13+
|
14+
LL | $( $v = $s::V.try_into().unwrap(), )*
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)