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 @@ mod error {
}
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 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
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 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
// 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, '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 @@ impl<'a, 'tcx> FnCtxt<'a, '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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
// 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 @@ 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) -> 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 @@ impl<'tcx> InferCtxt<'tcx> {
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 @@ impl<'tcx> InferCtxt<'tcx> {
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 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) {
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// 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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
] = 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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// 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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
}
_ => {
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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
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 @@ impl<'cx, 'tcx> SelectionContext<'cx, '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