Skip to content

Commit f42cdf7

Browse files
authored
Rollup merge of #100368 - chenyukang:fix-100321, r=lcnr
InferCtxt tainted_by_errors_flag should be Option<ErrorGuaranteed> Fixes #100321. Use Cell<Option<ErrorGuaranteed>> to guarantee that we emit an error when that flag is set.
2 parents 8733550 + f466a75 commit f42cdf7

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

compiler/rustc_infer/src/infer/at.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
7474
evaluation_cache: self.evaluation_cache.clone(),
7575
reported_trait_errors: self.reported_trait_errors.clone(),
7676
reported_closure_mismatch: self.reported_closure_mismatch.clone(),
77-
tainted_by_errors_flag: self.tainted_by_errors_flag.clone(),
77+
tainted_by_errors: self.tainted_by_errors.clone(),
7878
err_count_on_creation: self.err_count_on_creation,
7979
in_snapshot: self.in_snapshot.clone(),
8080
universe: self.universe.clone(),

compiler/rustc_infer/src/infer/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use rustc_middle::ty::IntVarValue;
3232
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
3333
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
3434
use rustc_span::symbol::Symbol;
35-
use rustc_span::Span;
35+
use rustc_span::{Span, DUMMY_SP};
3636

3737
use std::cell::{Cell, Ref, RefCell};
3838
use std::fmt;
@@ -316,12 +316,12 @@ pub struct InferCtxt<'a, 'tcx> {
316316
///
317317
/// Don't read this flag directly, call `is_tainted_by_errors()`
318318
/// and `set_tainted_by_errors()`.
319-
tainted_by_errors_flag: Cell<bool>,
319+
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
320320

321321
/// Track how many errors were reported when this infcx is created.
322322
/// If the number of errors increases, that's also a sign (line
323323
/// `tainted_by_errors`) to avoid reporting certain kinds of errors.
324-
// FIXME(matthewjasper) Merge into `tainted_by_errors_flag`
324+
// FIXME(matthewjasper) Merge into `tainted_by_errors`
325325
err_count_on_creation: usize,
326326

327327
/// This flag is true while there is an active snapshot.
@@ -624,7 +624,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
624624
evaluation_cache: Default::default(),
625625
reported_trait_errors: Default::default(),
626626
reported_closure_mismatch: Default::default(),
627-
tainted_by_errors_flag: Cell::new(false),
627+
tainted_by_errors: Cell::new(None),
628628
err_count_on_creation: tcx.sess.err_count(),
629629
in_snapshot: Cell::new(false),
630630
skip_leak_check: Cell::new(false),
@@ -1227,23 +1227,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12271227
pub fn is_tainted_by_errors(&self) -> bool {
12281228
debug!(
12291229
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
1230-
tainted_by_errors_flag={})",
1230+
tainted_by_errors={})",
12311231
self.tcx.sess.err_count(),
12321232
self.err_count_on_creation,
1233-
self.tainted_by_errors_flag.get()
1233+
self.tainted_by_errors.get().is_some()
12341234
);
12351235

12361236
if self.tcx.sess.err_count() > self.err_count_on_creation {
12371237
return true; // errors reported since this infcx was made
12381238
}
1239-
self.tainted_by_errors_flag.get()
1239+
self.tainted_by_errors.get().is_some()
12401240
}
12411241

12421242
/// Set the "tainted by errors" flag to true. We call this when we
12431243
/// observe an error from a prior pass.
12441244
pub fn set_tainted_by_errors(&self) {
12451245
debug!("set_tainted_by_errors()");
1246-
self.tainted_by_errors_flag.set(true)
1246+
self.tainted_by_errors.set(Some(
1247+
self.tcx.sess.delay_span_bug(DUMMY_SP, "`InferCtxt` incorrectly tainted by errors"),
1248+
));
12471249
}
12481250

12491251
pub fn skip_region_resolution(&self) {

compiler/rustc_trait_selection/src/traits/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,6 @@ pub fn impossible_predicates<'tcx>(
473473
debug!("impossible_predicates(predicates={:?})", predicates);
474474

475475
let result = tcx.infer_ctxt().enter(|infcx| {
476-
// HACK: Set tainted by errors to gracefully exit in case of overflow.
477-
infcx.set_tainted_by_errors();
478-
479476
let param_env = ty::ParamEnv::reveal_all();
480477
let ocx = ObligationCtxt::new(&infcx);
481478
let predicates = ocx.normalize(ObligationCause::dummy(), param_env, predicates);

0 commit comments

Comments
 (0)