diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index d04b9ac083ce..bb4ef2d7bd42 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -320,8 +320,13 @@ impl Session { self.diagnostic().abort_if_errors(); } pub fn compile_status(&self) -> Result<(), ErrorReported> { - compile_result_from_err_count(self.err_count()) + if self.has_errors() { + Err(ErrorReported) + } else { + Ok(()) + } } + // FIXME(matthewjasper) Remove this method, it should never be needed. pub fn track_errors(&self, f: F) -> Result where F: FnOnce() -> T, @@ -1388,11 +1393,3 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { } pub type CompileResult = Result<(), ErrorReported>; - -pub fn compile_result_from_err_count(err_count: usize) -> CompileResult { - if err_count == 0 { - Ok(()) - } else { - Err(ErrorReported) - } -} diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 05cee6dff230..082f981338a6 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -352,7 +352,7 @@ pub struct HandlerFlags { impl Drop for Handler { fn drop(&mut self) { - if self.err_count() == 0 { + if !self.has_errors() { let mut bugs = self.delayed_span_bugs.borrow_mut(); let has_bugs = !bugs.is_empty(); for bug in bugs.drain(..) { @@ -705,10 +705,9 @@ impl Handler { } pub fn abort_if_errors(&self) { - if self.err_count() == 0 { - return; + if self.has_errors() { + FatalError.raise(); } - FatalError.raise(); } pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) { if lvl == Warning && !self.flags.can_emit_warnings { diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 69cb696f4c58..c1b6e3409c91 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -959,7 +959,7 @@ fn analysis<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> Result<()> { // lot of annoying errors in the compile-fail tests (basically, // lint warnings and so on -- kindck used to do this abort, but // kindck is gone now). -nmatsakis - if sess.err_count() > 0 { + if sess.has_errors() { return Err(ErrorReported); } diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 8ca1b85ad9ae..85da32519714 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // else an error would have been flagged by the // `loops` pass for using break with an expression // where you are not supposed to. - assert!(expr_opt.is_none() || self.tcx.sess.err_count() > 0); + assert!(expr_opt.is_none() || self.tcx.sess.has_errors()); } ctxt.may_break = true; @@ -577,10 +577,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // this can only happen if the `break` was not // inside a loop at all, which is caught by the // loop-checking pass. - if self.tcx.sess.err_count() == 0 { - self.tcx.sess.delay_span_bug(expr.span, - "break was outside loop, but no error was emitted"); - } + self.tcx.sess.delay_span_bug(expr.span, + "break was outside loop, but no error was emitted"); // We still need to assign a type to the inner expression to // prevent the ICE in #43162. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0e83db48284a..40812b6a952d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2129,8 +2129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self.tcx.sess } - pub fn err_count_since_creation(&self) -> usize { - self.tcx.sess.err_count() - self.err_count_on_creation + pub fn errors_reported_since_creation(&self) -> bool { + self.tcx.sess.err_count() > self.err_count_on_creation } /// 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 } else if let ty::Error = leaf_ty.sty { // If there is already another error, do not emit // an error for not using a type Parameter. - assert!(tcx.sess.err_count() > 0); + assert!(tcx.sess.has_errors()); return; } } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 5c710399446e..5313e1d0f73a 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // standalone expr (e.g., the `E` in a type like `[u32; E]`). rcx.outlives_environment.save_implied_bounds(id); - if self.err_count_since_creation() == 0 { + if !self.errors_reported_since_creation() { // regionck assumes typeck succeeded rcx.visit_body(body); rcx.visit_region_obligations(id); @@ -173,7 +173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.param_env, ); - if self.err_count_since_creation() == 0 { + if !self.errors_reported_since_creation() { // regionck assumes typeck succeeded rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id)); } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 20a4f86aedb9..621292a13c83 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -346,7 +346,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt // current architecture. let resolver = abort_on_err(compiler.expansion(), sess).peek().1.clone(); - if sess.err_count() > 0 { + if sess.has_errors() { sess.fatal("Compilation failed, aborting rustdoc"); }