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>) { pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
self.tainted_by_errors = Some( if let None = self.tainted_by_errors {
self.tcx.sess.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"), self.tainted_by_errors = Some(
); self.tcx
.sess
.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
)
}
t.buffer(&mut self.buffered); t.buffer(&mut self.buffered);
} }

View file

@ -219,7 +219,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
instantiated_ty: OpaqueHiddenType<'tcx>, instantiated_ty: OpaqueHiddenType<'tcx>,
origin: OpaqueTyOrigin, origin: OpaqueTyOrigin,
) -> Ty<'tcx> { ) -> 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); 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 // type, `?T` is not considered unsolved, but `?I` is. The
// same is true for float variables.) // same is true for float variables.)
let fallback = match ty.kind() { 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::IntVar(_)) => self.tcx.types.i32,
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64, ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
_ => match diverging_fallback.get(&ty) { _ => 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> { pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => t, 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 => { None => {
bug!( bug!(
"no type for node {}: {} in fcx {}", "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>> { pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t), 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, None => None,
} }
} }
@ -1440,7 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !ty.is_ty_var() { if !ty.is_ty_var() {
ty ty
} else { } else {
if let None = self.is_tainted_by_errors() { if let None = self.tainted_by_errors() {
self.err_ctxt() self.err_ctxt()
.emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true) .emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true)
.emit(); .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.typeck_results.borrow().expr_ty_adjusted(expr);
let ty = self.resolve_vars_if_possible(ty); let ty = self.resolve_vars_if_possible(ty);
if ty.has_non_region_infer() { if ty.has_non_region_infer() {
assert!(self.tainted_by_errors().is_some());
self.tcx.ty_error() self.tcx.ty_error()
} else { } else {
self.tcx.erase_regions(ty) self.tcx.erase_regions(ty)

View file

@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>(
fcx.select_all_obligations_or_error(); 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(); fcx.check_transmutes();
} }

View file

@ -133,7 +133,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
} }
fn is_tainted_by_errors(&self) -> bool { 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( 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 = wbcx.typeck_results.treat_byte_string_as_slice =
mem::take(&mut self.typeck_results.borrow_mut().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); 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 // 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. // users of the typeck results don't produce extra errors, or worse, ICEs.
if let Some(e) = resolver.replaced_with_error { 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); 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 /// reporting errors that often occur as a result of earlier
/// errors, but where it's hard to be 100% sure (e.g., unresolved /// errors, but where it's hard to be 100% sure (e.g., unresolved
/// inference variables, regionck errors). /// 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!( debug!(
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \ "is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
tainted_by_errors={})", tainted_by_errors={})",
@ -1217,14 +1218,17 @@ impl<'tcx> InferCtxt<'tcx> {
self.tainted_by_errors.get().is_some() 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 { if self.tcx.sess.err_count() > self.err_count_on_creation {
// errors reported since this infcx was made // errors reported since this infcx was made
return Some(self.tcx.sess.delay_span_bug( self.set_tainted_by_errors();
DUMMY_SP, return self.tainted_by_errors.get();
"`tcx.sess.error_count()` incorrectly returned non zero value",
));
} }
self.tainted_by_errors.get()
None
} }
/// Set the "tainted by errors" flag to true. We call this when we /// 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 mut inner = self.inner.borrow_mut();
let inner = &mut *inner; let inner = &mut *inner;
assert!( 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: {:#?}", "region_obligations not empty: {:#?}",
inner.region_obligations inner.region_obligations
); );
@ -1711,7 +1715,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) { ) {
let errors = self.resolve_regions(outlives_env); 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 // As a heuristic, just skip reporting region errors
// altogether if other errors have been reported while // altogether if other errors have been reported while
// this infcx was in use. This is totally hokey but // 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 // check upstream for type errors and don't add the obligations to
// begin with in those cases. // begin with in those cases.
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) { 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( self.emit_inference_failure_err(
body_id, body_id,
span, span,
@ -2115,14 +2115,16 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if impls.len() > 1 && impls.len() < 5 && has_non_region_infer { if impls.len() > 1 && impls.len() < 5 && has_non_region_infer {
self.annotate_source_of_ambiguity(&mut err, &impls, predicate); self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
} else { } else {
if self.is_tainted_by_errors().is_some() { if self.tainted_by_errors().is_some() {
err.cancel();
return; return;
} }
err.note(&format!("cannot satisfy `{}`", predicate)); err.note(&format!("cannot satisfy `{}`", predicate));
} }
} }
_ => { _ => {
if self.is_tainted_by_errors().is_some() { if self.tainted_by_errors().is_some() {
err.cancel();
return; return;
} }
err.note(&format!("cannot satisfy `{}`", predicate)); err.note(&format!("cannot satisfy `{}`", predicate));
@ -2224,7 +2226,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
] = path.segments ] = path.segments
&& data.trait_ref.def_id == *trait_id && data.trait_ref.def_id == *trait_id
&& self.tcx.trait_of_item(*item_id) == Some(*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 { let (verb, noun) = match self.tcx.associated_item(item_id).kind {
ty::AssocKind::Const => ("refer to the", "constant"), ty::AssocKind::Const => ("refer to the", "constant"),
@ -2293,7 +2295,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// with error messages. // with error messages.
if arg.references_error() if arg.references_error()
|| self.tcx.sess.has_errors().is_some() || self.tcx.sess.has_errors().is_some()
|| self.is_tainted_by_errors().is_some() || self.tainted_by_errors().is_some()
{ {
return; return;
} }
@ -2304,7 +2306,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ty::PredicateKind::Subtype(data) => { ty::PredicateKind::Subtype(data) => {
if data.references_error() if data.references_error()
|| self.tcx.sess.has_errors().is_some() || 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 // no need to overload user in such cases
return; 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) self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true)
} }
ty::PredicateKind::Projection(data) => { 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; return;
} }
let subst = data let subst = data
@ -2349,7 +2351,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
ty::PredicateKind::ConstEvaluatable(data) => { 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; return;
} }
let subst = data.walk().find(|g| g.is_non_region_infer()); 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; return;
} }
let mut err = struct_span_err!( let mut err = struct_span_err!(
@ -2420,7 +2422,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
post.sort(); post.sort();
post.dedup(); post.dedup();
if self.is_tainted_by_errors().is_some() if self.tainted_by_errors().is_some()
&& (crate_names.len() == 1 && (crate_names.len() == 1
&& spans.len() == 0 && spans.len() == 0
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str()) && ["`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) { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
match self.query_mode { match self.query_mode {
TraitQueryMode::Standard => { 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)); return Err(OverflowError::Error(e));
} }
self.infcx.err_ctxt().report_overflow_error(error_obligation, true); 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)] #[derive(Debug)]
enum MyError { enum MyError {
NotFound { key: Vec<u8> }, NotFound { key: Vec<u8> },

View file

@ -1,5 +1,5 @@
error[E0507]: cannot move out of `*key` which is behind a shared reference 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() LL | String::from_utf8(*key).unwrap()
| ^^^^ move occurs because `*key` has type `Vec<u8>`, which does not implement the `Copy` trait | ^^^^ move occurs because `*key` has type `Vec<u8>`, which does not implement the `Copy` trait