1
Fork 0

Rollup merge of #104554 - BoxyUwU:less_unchecked_pls, r=lcnr

Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less

there are only like 3 or 4 call sites left after this but it wasnt obvious to me how to remove them
This commit is contained in:
Dylan DPC 2022-11-19 11:54:45 +05:30 committed by GitHub
commit 7f35493e99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 173 additions and 126 deletions

View file

@ -34,7 +34,7 @@ pub use rustc_middle::ty::IntVarValue;
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use rustc_span::Span;
use std::cell::{Cell, RefCell};
use std::fmt;
@ -1208,7 +1208,8 @@ impl<'tcx> InferCtxt<'tcx> {
/// reporting errors that often occur as a result of earlier
/// errors, but where it's hard to be 100% sure (e.g., unresolved
/// inference variables, regionck errors).
pub fn is_tainted_by_errors(&self) -> bool {
#[must_use = "this method does not have any side effects"]
pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
debug!(
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
tainted_by_errors={})",
@ -1217,19 +1218,25 @@ impl<'tcx> InferCtxt<'tcx> {
self.tainted_by_errors.get().is_some()
);
if self.tcx.sess.err_count() > self.err_count_on_creation {
return true; // errors reported since this infcx was made
if let Some(e) = self.tainted_by_errors.get() {
return Some(e);
}
self.tainted_by_errors.get().is_some()
if self.tcx.sess.err_count() > self.err_count_on_creation {
// errors reported since this infcx was made
let e = self.tcx.sess.has_errors().unwrap();
self.set_tainted_by_errors(e);
return Some(e);
}
None
}
/// Set the "tainted by errors" flag to true. We call this when we
/// observe an error from a prior pass.
pub fn set_tainted_by_errors(&self) {
debug!("set_tainted_by_errors()");
self.tainted_by_errors.set(Some(
self.tcx.sess.delay_span_bug(DUMMY_SP, "`InferCtxt` incorrectly tainted by errors"),
));
pub fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {
debug!("set_tainted_by_errors(ErrorGuaranteed)");
self.tainted_by_errors.set(Some(e));
}
pub fn skip_region_resolution(&self) {
@ -1270,7 +1277,7 @@ impl<'tcx> InferCtxt<'tcx> {
let mut inner = self.inner.borrow_mut();
let inner = &mut *inner;
assert!(
self.is_tainted_by_errors() || inner.region_obligations.is_empty(),
self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
"region_obligations not empty: {:#?}",
inner.region_obligations
);
@ -1707,7 +1714,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) {
let errors = self.resolve_regions(outlives_env);
if !self.is_tainted_by_errors() {
if let None = self.tainted_by_errors() {
// As a heuristic, just skip reporting region errors
// altogether if other errors have been reported while
// this infcx was in use. This is totally hokey but

View file

@ -116,9 +116,9 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
Ok(a)
}
(&ty::Error(_), _) | (_, &ty::Error(_)) => {
infcx.set_tainted_by_errors();
Ok(self.tcx().ty_error())
(&ty::Error(e), _) | (_, &ty::Error(e)) => {
infcx.set_tainted_by_errors(e);
Ok(self.tcx().ty_error_with_guaranteed(e))
}
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {