Tweak error counting.
We have several methods indicating the presence of errors, lint errors, and delayed bugs. I find it frustrating that it's very unclear which one you should use in any particular spot. This commit attempts to instill a basic principle of "use the least general one possible", because that reflects reality in practice -- `has_errors` is the least general one and has by far the most uses (esp. via `abort_if_errors`). Specifics: - Add some comments giving some usage guidelines. - Prefer `has_errors` to comparing `err_count` to zero. - Remove `has_errors_or_span_delayed_bugs` because it's a weird one: in the cases where we need to count delayed bugs, we should really be counting lint errors as well. - Rename `is_compilation_going_to_fail` as `has_errors_or_lint_errors_or_span_delayed_bugs`, for consistency with `has_errors` and `has_errors_or_lint_errors`. - Change a few other `has_errors_or_lint_errors` calls to `has_errors`, as per the "least general" principle. This didn't turn out to be as neat as I hoped when I started, but I think it's still an improvement.
This commit is contained in:
parent
807c8687de
commit
1f9fa2305a
14 changed files with 35 additions and 32 deletions
|
@ -117,9 +117,9 @@ fn escape_literal(s: &str) -> String {
|
|||
/// field is only populated during an in-progress typeck.
|
||||
/// Get an instance by calling `InferCtxt::err_ctxt` or `FnCtxt::err_ctxt`.
|
||||
///
|
||||
/// You must only create this if you intend to actually emit an error.
|
||||
/// This provides a lot of utility methods which should not be used
|
||||
/// during the happy path.
|
||||
/// You must only create this if you intend to actually emit an error (or
|
||||
/// perhaps a warning, though preferably not.) It provides a lot of utility
|
||||
/// methods which should not be used during the happy path.
|
||||
pub struct TypeErrCtxt<'a, 'tcx> {
|
||||
pub infcx: &'a InferCtxt<'tcx>,
|
||||
pub typeck_results: Option<std::cell::Ref<'a, ty::TypeckResults<'tcx>>>,
|
||||
|
@ -133,9 +133,10 @@ pub struct TypeErrCtxt<'a, 'tcx> {
|
|||
|
||||
impl Drop for TypeErrCtxt<'_, '_> {
|
||||
fn drop(&mut self) {
|
||||
if let Some(_) = self.dcx().has_errors_or_span_delayed_bugs() {
|
||||
// ok, emitted an error.
|
||||
if self.dcx().has_errors().is_some() {
|
||||
// Ok, emitted an error.
|
||||
} else {
|
||||
// Didn't emit an error; maybe it was created but not yet emitted.
|
||||
self.infcx
|
||||
.tcx
|
||||
.sess
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue