1
Fork 0

require an ErrorGuaranteed to taint infcx with errors

This commit is contained in:
Boxy 2022-11-18 11:30:21 +00:00
parent 1c48039a87
commit 9ed348376f
15 changed files with 94 additions and 59 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;
@ -1224,8 +1224,9 @@ impl<'tcx> InferCtxt<'tcx> {
if self.tcx.sess.err_count() > self.err_count_on_creation {
// errors reported since this infcx was made
self.set_tainted_by_errors();
return self.tainted_by_errors.get();
let e = self.tcx.sess.has_errors().unwrap();
self.set_tainted_by_errors(e);
return Some(e);
}
None
@ -1233,11 +1234,9 @@ impl<'tcx> InferCtxt<'tcx> {
/// 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) {

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 => {