Skip to content

Commit 9c51004

Browse files
committed
InferCtxt::is_tainted_by_errors returns ErrorGuaranteed
1 parent c1ec8ff commit 9c51004

File tree

10 files changed

+33
-35
lines changed

10 files changed

+33
-35
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate tracing;
1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2020
use rustc_data_structures::graph::dominators::Dominators;
2121
use rustc_data_structures::vec_map::VecMap;
22-
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
22+
use rustc_errors::{Diagnostic, DiagnosticBuilder};
2323
use rustc_hir as hir;
2424
use rustc_hir::def_id::LocalDefId;
2525
use rustc_index::bit_set::ChunkedBitSet;

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
219219
instantiated_ty: OpaqueHiddenType<'tcx>,
220220
origin: OpaqueTyOrigin,
221221
) -> Ty<'tcx> {
222-
if self.is_tainted_by_errors() {
223-
return self.tcx.ty_error();
222+
if let Some(e) = self.is_tainted_by_errors() {
223+
return self.tcx.ty_error_with_guaranteed(e);
224224
}
225225

226226
let definition_ty = instantiated_ty

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
104104
// type, `?T` is not considered unsolved, but `?I` is. The
105105
// same is true for float variables.)
106106
let fallback = match ty.kind() {
107-
_ if self.is_tainted_by_errors() => self.tcx.ty_error(),
107+
_ if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
108108
ty::Infer(ty::IntVar(_)) => self.tcx.types.i32,
109109
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
110110
_ => match diverging_fallback.get(&ty) {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
528528
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
529529
match self.typeck_results.borrow().node_types().get(id) {
530530
Some(&t) => t,
531-
None if self.is_tainted_by_errors() => self.tcx.ty_error(),
531+
None if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
532532
None => {
533533
bug!(
534534
"no type for node {}: {} in fcx {}",
@@ -543,7 +543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
543543
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
544544
match self.typeck_results.borrow().node_types().get(id) {
545545
Some(&t) => Some(t),
546-
None if self.is_tainted_by_errors() => Some(self.tcx.ty_error()),
546+
None if let Some(e) = self.is_tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)),
547547
None => None,
548548
}
549549
}
@@ -1440,7 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14401440
if !ty.is_ty_var() {
14411441
ty
14421442
} else {
1443-
if !self.is_tainted_by_errors() {
1443+
if let None = self.is_tainted_by_errors() {
14441444
self.err_ctxt()
14451445
.emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true)
14461446
.emit();

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>(
344344

345345
fcx.select_all_obligations_or_error();
346346

347-
if !fcx.infcx.is_tainted_by_errors() {
347+
if let None = fcx.infcx.is_tainted_by_errors() {
348348
fcx.check_transmutes();
349349
}
350350

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
133133
}
134134

135135
fn is_tainted_by_errors(&self) -> bool {
136-
self.infcx.is_tainted_by_errors()
136+
self.infcx.is_tainted_by_errors().is_some()
137137
}
138138

139139
fn resolve_type_vars_or_error(

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383
wbcx.typeck_results.treat_byte_string_as_slice =
8484
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
8585

86-
if self.is_tainted_by_errors() {
87-
// FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted.
88-
wbcx.typeck_results.tainted_by_errors =
89-
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
86+
if let Some(e) = self.is_tainted_by_errors() {
87+
wbcx.typeck_results.tainted_by_errors = Some(e);
9088
}
9189

9290
debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results);

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl<'tcx> InferCtxt<'tcx> {
12081208
/// reporting errors that often occur as a result of earlier
12091209
/// errors, but where it's hard to be 100% sure (e.g., unresolved
12101210
/// inference variables, regionck errors).
1211-
pub fn is_tainted_by_errors(&self) -> bool {
1211+
pub fn is_tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
12121212
debug!(
12131213
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
12141214
tainted_by_errors={})",
@@ -1218,9 +1218,13 @@ impl<'tcx> InferCtxt<'tcx> {
12181218
);
12191219

12201220
if self.tcx.sess.err_count() > self.err_count_on_creation {
1221-
return true; // errors reported since this infcx was made
1221+
// errors reported since this infcx was made
1222+
return Some(self.tcx.sess.delay_span_bug(
1223+
DUMMY_SP,
1224+
"`tcx.sess.error_count()` incorrectly returned non zero value",
1225+
));
12221226
}
1223-
self.tainted_by_errors.get().is_some()
1227+
self.tainted_by_errors.get()
12241228
}
12251229

12261230
/// Set the "tainted by errors" flag to true. We call this when we
@@ -1270,7 +1274,7 @@ impl<'tcx> InferCtxt<'tcx> {
12701274
let mut inner = self.inner.borrow_mut();
12711275
let inner = &mut *inner;
12721276
assert!(
1273-
self.is_tainted_by_errors() || inner.region_obligations.is_empty(),
1277+
self.is_tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
12741278
"region_obligations not empty: {:#?}",
12751279
inner.region_obligations
12761280
);
@@ -1707,7 +1711,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17071711
) {
17081712
let errors = self.resolve_regions(outlives_env);
17091713

1710-
if !self.is_tainted_by_errors() {
1714+
if let None = self.is_tainted_by_errors() {
17111715
// As a heuristic, just skip reporting region errors
17121716
// altogether if other errors have been reported while
17131717
// this infcx was in use. This is totally hokey but

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20602060
// check upstream for type errors and don't add the obligations to
20612061
// begin with in those cases.
20622062
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
2063-
if !self.is_tainted_by_errors() {
2063+
if let None = self.is_tainted_by_errors() {
20642064
self.emit_inference_failure_err(
20652065
body_id,
20662066
span,
@@ -2115,16 +2115,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21152115
if impls.len() > 1 && impls.len() < 5 && has_non_region_infer {
21162116
self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
21172117
} else {
2118-
if self.is_tainted_by_errors() {
2119-
err.delay_as_bug();
2118+
if self.is_tainted_by_errors().is_some() {
21202119
return;
21212120
}
21222121
err.note(&format!("cannot satisfy `{}`", predicate));
21232122
}
21242123
}
21252124
_ => {
2126-
if self.is_tainted_by_errors() {
2127-
err.delay_as_bug();
2125+
if self.is_tainted_by_errors().is_some() {
21282126
return;
21292127
}
21302128
err.note(&format!("cannot satisfy `{}`", predicate));
@@ -2226,7 +2224,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22262224
] = path.segments
22272225
&& data.trait_ref.def_id == *trait_id
22282226
&& self.tcx.trait_of_item(*item_id) == Some(*trait_id)
2229-
&& !self.is_tainted_by_errors()
2227+
&& let None = self.is_tainted_by_errors()
22302228
{
22312229
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
22322230
ty::AssocKind::Const => ("refer to the", "constant"),
@@ -2295,7 +2293,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22952293
// with error messages.
22962294
if arg.references_error()
22972295
|| self.tcx.sess.has_errors().is_some()
2298-
|| self.is_tainted_by_errors()
2296+
|| self.is_tainted_by_errors().is_some()
22992297
{
23002298
return;
23012299
}
@@ -2306,7 +2304,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23062304
ty::PredicateKind::Subtype(data) => {
23072305
if data.references_error()
23082306
|| self.tcx.sess.has_errors().is_some()
2309-
|| self.is_tainted_by_errors()
2307+
|| self.is_tainted_by_errors().is_some()
23102308
{
23112309
// no need to overload user in such cases
23122310
return;
@@ -2317,7 +2315,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23172315
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true)
23182316
}
23192317
ty::PredicateKind::Projection(data) => {
2320-
if predicate.references_error() || self.is_tainted_by_errors() {
2318+
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
23212319
return;
23222320
}
23232321
let subst = data
@@ -2351,7 +2349,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23512349
}
23522350

23532351
ty::PredicateKind::ConstEvaluatable(data) => {
2354-
if predicate.references_error() || self.is_tainted_by_errors() {
2352+
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
23552353
return;
23562354
}
23572355
let subst = data.walk().find(|g| g.is_non_region_infer());
@@ -2378,7 +2376,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23782376
}
23792377
}
23802378
_ => {
2381-
if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors() {
2379+
if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors().is_some() {
23822380
return;
23832381
}
23842382
let mut err = struct_span_err!(
@@ -2422,7 +2420,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24222420
post.sort();
24232421
post.dedup();
24242422

2425-
if self.is_tainted_by_errors()
2423+
if self.is_tainted_by_errors().is_some()
24262424
&& (crate_names.len() == 1
24272425
&& spans.len() == 0
24282426
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::traits::ProjectionCacheKey;
3333
use rustc_data_structures::fx::FxHashMap;
3434
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
3535
use rustc_data_structures::stack::ensure_sufficient_stack;
36-
use rustc_errors::{Diagnostic, ErrorGuaranteed};
36+
use rustc_errors::Diagnostic;
3737
use rustc_hir as hir;
3838
use rustc_hir::def_id::DefId;
3939
use rustc_infer::infer::LateBoundRegionConversionTime;
@@ -1089,10 +1089,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10891089
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
10901090
match self.query_mode {
10911091
TraitQueryMode::Standard => {
1092-
if self.infcx.is_tainted_by_errors() {
1093-
return Err(OverflowError::Error(
1094-
ErrorGuaranteed::unchecked_claim_error_was_emitted(),
1095-
));
1092+
if let Some(e) = self.infcx.is_tainted_by_errors() {
1093+
return Err(OverflowError::Error(e));
10961094
}
10971095
self.infcx.err_ctxt().report_overflow_error(error_obligation, true);
10981096
}

0 commit comments

Comments
 (0)