Prefer to use has_errors
to err_count
This commit is contained in:
parent
f693d339f1
commit
30b6c59f24
7 changed files with 19 additions and 25 deletions
|
@ -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<F, T>(&self, f: F) -> Result<T, ErrorReported>
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue