rename is_tainted_by_errors

This commit is contained in:
Boxy 2022-11-18 10:25:32 +00:00
parent 3fca95a597
commit 1c48039a87
13 changed files with 42 additions and 33 deletions

View File

@ -2294,9 +2294,13 @@ pub fn new(tcx: TyCtxt<'tcx>) -> Self {
}
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
self.tainted_by_errors = Some(
self.tcx.sess.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
);
if let None = self.tainted_by_errors {
self.tainted_by_errors = Some(
self.tcx
.sess
.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
)
}
t.buffer(&mut self.buffered);
}

View File

@ -219,7 +219,7 @@ fn infer_opaque_definition_from_instantiation(
instantiated_ty: OpaqueHiddenType<'tcx>,
origin: OpaqueTyOrigin,
) -> Ty<'tcx> {
if let Some(e) = self.is_tainted_by_errors() {
if let Some(e) = self.tainted_by_errors() {
return self.tcx.ty_error_with_guaranteed(e);
}

View File

@ -104,7 +104,7 @@ fn fallback_if_possible(
// type, `?T` is not considered unsolved, but `?I` is. The
// same is true for float variables.)
let fallback = match ty.kind() {
_ if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
_ if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
ty::Infer(ty::IntVar(_)) => self.tcx.types.i32,
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
_ => match diverging_fallback.get(&ty) {

View File

@ -528,7 +528,7 @@ fn can_contain_user_lifetime_bounds<T>(t: T) -> bool
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => t,
None if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
None => {
bug!(
"no type for node {}: {} in fcx {}",
@ -543,7 +543,7 @@ pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t),
None if let Some(e) = self.is_tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)),
None if let Some(e) = self.tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)),
None => None,
}
}
@ -1440,7 +1440,7 @@ pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
if !ty.is_ty_var() {
ty
} else {
if let None = self.is_tainted_by_errors() {
if let None = self.tainted_by_errors() {
self.err_ctxt()
.emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true)
.emit();

View File

@ -73,6 +73,7 @@ pub(in super::super) fn check_asms(&self) {
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
let ty = self.resolve_vars_if_possible(ty);
if ty.has_non_region_infer() {
assert!(self.tainted_by_errors().is_some());
self.tcx.ty_error()
} else {
self.tcx.erase_regions(ty)

View File

@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>(
fcx.select_all_obligations_or_error();
if let None = fcx.infcx.is_tainted_by_errors() {
if let None = fcx.infcx.tainted_by_errors() {
fcx.check_transmutes();
}

View File

@ -133,7 +133,7 @@ fn resolve_vars_if_possible<T>(&self, value: T) -> T
}
fn is_tainted_by_errors(&self) -> bool {
self.infcx.is_tainted_by_errors().is_some()
self.infcx.tainted_by_errors().is_some()
}
fn resolve_type_vars_or_error(

View File

@ -83,7 +83,7 @@ pub fn resolve_type_vars_in_body(
wbcx.typeck_results.treat_byte_string_as_slice =
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
if let Some(e) = self.is_tainted_by_errors() {
if let Some(e) = self.tainted_by_errors() {
wbcx.typeck_results.tainted_by_errors = Some(e);
}
@ -673,7 +673,6 @@ fn resolve<T>(&mut self, x: T, span: &dyn Locatable) -> T
// to mark the `TypeckResults` as tainted in that case, so that downstream
// users of the typeck results don't produce extra errors, or worse, ICEs.
if let Some(e) = resolver.replaced_with_error {
// FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted.
self.typeck_results.tainted_by_errors = Some(e);
}

View File

@ -1208,7 +1208,8 @@ pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'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) -> Option<ErrorGuaranteed> {
#[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,14 +1218,17 @@ pub fn is_tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
self.tainted_by_errors.get().is_some()
);
if let Some(e) = self.tainted_by_errors.get() {
return Some(e);
}
if self.tcx.sess.err_count() > self.err_count_on_creation {
// errors reported since this infcx was made
return Some(self.tcx.sess.delay_span_bug(
DUMMY_SP,
"`tcx.sess.error_count()` incorrectly returned non zero value",
));
self.set_tainted_by_errors();
return self.tainted_by_errors.get();
}
self.tainted_by_errors.get()
None
}
/// Set the "tainted by errors" flag to true. We call this when we
@ -1274,7 +1278,7 @@ pub fn resolve_regions(
let mut inner = self.inner.borrow_mut();
let inner = &mut *inner;
assert!(
self.is_tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
"region_obligations not empty: {:#?}",
inner.region_obligations
);
@ -1711,7 +1715,7 @@ pub fn resolve_regions_and_report_errors(
) {
let errors = self.resolve_regions(outlives_env);
if let None = 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

@ -2060,7 +2060,7 @@ fn maybe_report_ambiguity(
// check upstream for type errors and don't add the obligations to
// begin with in those cases.
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
if let None = self.is_tainted_by_errors() {
if let None = self.tainted_by_errors() {
self.emit_inference_failure_err(
body_id,
span,
@ -2115,14 +2115,16 @@ fn maybe_report_ambiguity(
if impls.len() > 1 && impls.len() < 5 && has_non_region_infer {
self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
} else {
if self.is_tainted_by_errors().is_some() {
if self.tainted_by_errors().is_some() {
err.cancel();
return;
}
err.note(&format!("cannot satisfy `{}`", predicate));
}
}
_ => {
if self.is_tainted_by_errors().is_some() {
if self.tainted_by_errors().is_some() {
err.cancel();
return;
}
err.note(&format!("cannot satisfy `{}`", predicate));
@ -2224,7 +2226,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
] = path.segments
&& data.trait_ref.def_id == *trait_id
&& self.tcx.trait_of_item(*item_id) == Some(*trait_id)
&& let None = self.is_tainted_by_errors()
&& let None = self.tainted_by_errors()
{
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
ty::AssocKind::Const => ("refer to the", "constant"),
@ -2293,7 +2295,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
// with error messages.
if arg.references_error()
|| self.tcx.sess.has_errors().is_some()
|| self.is_tainted_by_errors().is_some()
|| self.tainted_by_errors().is_some()
{
return;
}
@ -2304,7 +2306,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
ty::PredicateKind::Subtype(data) => {
if data.references_error()
|| self.tcx.sess.has_errors().is_some()
|| self.is_tainted_by_errors().is_some()
|| self.tainted_by_errors().is_some()
{
// no need to overload user in such cases
return;
@ -2315,7 +2317,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true)
}
ty::PredicateKind::Projection(data) => {
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
if predicate.references_error() || self.tainted_by_errors().is_some() {
return;
}
let subst = data
@ -2349,7 +2351,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
}
ty::PredicateKind::ConstEvaluatable(data) => {
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
if predicate.references_error() || self.tainted_by_errors().is_some() {
return;
}
let subst = data.walk().find(|g| g.is_non_region_infer());
@ -2376,7 +2378,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
}
}
_ => {
if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors().is_some() {
if self.tcx.sess.has_errors().is_some() || self.tainted_by_errors().is_some() {
return;
}
let mut err = struct_span_err!(
@ -2420,7 +2422,7 @@ fn annotate_source_of_ambiguity(
post.sort();
post.dedup();
if self.is_tainted_by_errors().is_some()
if self.tainted_by_errors().is_some()
&& (crate_names.len() == 1
&& spans.len() == 0
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())

View File

@ -1089,7 +1089,7 @@ fn check_recursion_depth<T: Display + TypeFoldable<'tcx>>(
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
match self.query_mode {
TraitQueryMode::Standard => {
if let Some(e) = self.infcx.is_tainted_by_errors() {
if let Some(e) = self.infcx.tainted_by_errors() {
return Err(OverflowError::Error(e));
}
self.infcx.err_ctxt().report_overflow_error(error_obligation, true);

View File

@ -1,4 +1,3 @@
// compile-flags:-Ztreat-err-as-bug=5
#[derive(Debug)]
enum MyError {
NotFound { key: Vec<u8> },

View File

@ -1,5 +1,5 @@
error[E0507]: cannot move out of `*key` which is behind a shared reference
--> $DIR/issue-52262.rs:16:35
--> $DIR/issue-52262.rs:15:35
|
LL | String::from_utf8(*key).unwrap()
| ^^^^ move occurs because `*key` has type `Vec<u8>`, which does not implement the `Copy` trait