Skip to content

Commit 30b6c59

Browse files
committed
Prefer to use has_errors to err_count
1 parent f693d33 commit 30b6c59

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

src/librustc/session/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,13 @@ impl Session {
320320
self.diagnostic().abort_if_errors();
321321
}
322322
pub fn compile_status(&self) -> Result<(), ErrorReported> {
323-
compile_result_from_err_count(self.err_count())
323+
if self.has_errors() {
324+
Err(ErrorReported)
325+
} else {
326+
Ok(())
327+
}
324328
}
329+
// FIXME(matthewjasper) Remove this method, it should never be needed.
325330
pub fn track_errors<F, T>(&self, f: F) -> Result<T, ErrorReported>
326331
where
327332
F: FnOnce() -> T,
@@ -1388,11 +1393,3 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
13881393
}
13891394

13901395
pub type CompileResult = Result<(), ErrorReported>;
1391-
1392-
pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
1393-
if err_count == 0 {
1394-
Ok(())
1395-
} else {
1396-
Err(ErrorReported)
1397-
}
1398-
}

src/librustc_errors/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub struct HandlerFlags {
352352

353353
impl Drop for Handler {
354354
fn drop(&mut self) {
355-
if self.err_count() == 0 {
355+
if !self.has_errors() {
356356
let mut bugs = self.delayed_span_bugs.borrow_mut();
357357
let has_bugs = !bugs.is_empty();
358358
for bug in bugs.drain(..) {
@@ -705,10 +705,9 @@ impl Handler {
705705
}
706706

707707
pub fn abort_if_errors(&self) {
708-
if self.err_count() == 0 {
709-
return;
708+
if self.has_errors() {
709+
FatalError.raise();
710710
}
711-
FatalError.raise();
712711
}
713712
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
714713
if lvl == Warning && !self.flags.can_emit_warnings {

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ fn analysis<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> Result<()> {
959959
// lot of annoying errors in the compile-fail tests (basically,
960960
// lint warnings and so on -- kindck used to do this abort, but
961961
// kindck is gone now). -nmatsakis
962-
if sess.err_count() > 0 {
962+
if sess.has_errors() {
963963
return Err(ErrorReported);
964964
}
965965

src/librustc_typeck/check/expr.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
565565
// else an error would have been flagged by the
566566
// `loops` pass for using break with an expression
567567
// where you are not supposed to.
568-
assert!(expr_opt.is_none() || self.tcx.sess.err_count() > 0);
568+
assert!(expr_opt.is_none() || self.tcx.sess.has_errors());
569569
}
570570

571571
ctxt.may_break = true;
@@ -577,10 +577,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
577577
// this can only happen if the `break` was not
578578
// inside a loop at all, which is caught by the
579579
// loop-checking pass.
580-
if self.tcx.sess.err_count() == 0 {
581-
self.tcx.sess.delay_span_bug(expr.span,
582-
"break was outside loop, but no error was emitted");
583-
}
580+
self.tcx.sess.delay_span_bug(expr.span,
581+
"break was outside loop, but no error was emitted");
584582

585583
// We still need to assign a type to the inner expression to
586584
// prevent the ICE in #43162.

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2129,8 +2129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21292129
&self.tcx.sess
21302130
}
21312131

2132-
pub fn err_count_since_creation(&self) -> usize {
2133-
self.tcx.sess.err_count() - self.err_count_on_creation
2132+
pub fn errors_reported_since_creation(&self) -> bool {
2133+
self.tcx.sess.err_count() > self.err_count_on_creation
21342134
}
21352135

21362136
/// Produces warning on the given node, if the current point in the
@@ -4376,7 +4376,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t
43764376
} else if let ty::Error = leaf_ty.sty {
43774377
// If there is already another error, do not emit
43784378
// an error for not using a type Parameter.
4379-
assert!(tcx.sess.err_count() > 0);
4379+
assert!(tcx.sess.has_errors());
43804380
return;
43814381
}
43824382
}

src/librustc_typeck/check/regionck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
123123
// standalone expr (e.g., the `E` in a type like `[u32; E]`).
124124
rcx.outlives_environment.save_implied_bounds(id);
125125

126-
if self.err_count_since_creation() == 0 {
126+
if !self.errors_reported_since_creation() {
127127
// regionck assumes typeck succeeded
128128
rcx.visit_body(body);
129129
rcx.visit_region_obligations(id);
@@ -173,7 +173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
173173
self.param_env,
174174
);
175175

176-
if self.err_count_since_creation() == 0 {
176+
if !self.errors_reported_since_creation() {
177177
// regionck assumes typeck succeeded
178178
rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id));
179179
}

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
346346
// current architecture.
347347
let resolver = abort_on_err(compiler.expansion(), sess).peek().1.clone();
348348

349-
if sess.err_count() > 0 {
349+
if sess.has_errors() {
350350
sess.fatal("Compilation failed, aborting rustdoc");
351351
}
352352

0 commit comments

Comments
 (0)