borrowck: move error tainting earlier

This commit is contained in:
lcnr 2025-08-08 19:16:03 +02:00
parent 2886b36df4
commit 8b95291cd4
3 changed files with 17 additions and 17 deletions

View file

@ -216,22 +216,11 @@ pub(crate) fn compute_sccs_applying_placeholder_outlives_constraints<'tcx>(
placeholder_index_to_region: _,
liveness_constraints,
mut outlives_constraints,
mut member_constraints,
member_constraints,
universe_causes,
type_tests,
} = constraints;
if let Some(guar) = universal_regions.tainted_by_errors() {
debug!("Universal regions tainted by errors; removing constraints!");
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
// outlives bounds that we may end up checking.
outlives_constraints = Default::default();
member_constraints = Default::default();
// Also taint the entire scope.
infcx.set_tainted_by_errors(guar);
}
let fr_static = universal_regions.fr_static;
let compute_sccs =
|constraints: &OutlivesConstraintSet<'tcx>,

View file

@ -182,6 +182,17 @@ pub(crate) fn type_check<'tcx>(
)
});
// In case type check encountered an error region, we suppress unhelpful extra
// errors in by clearing out all outlives bounds that we may end up checking.
if let Some(guar) = universal_region_relations.universal_regions.encountered_re_error() {
debug!("encountered an error region; removing constraints!");
constraints.outlives_constraints = Default::default();
constraints.member_constraints = Default::default();
constraints.type_tests = Default::default();
root_cx.set_tainted_by_errors(guar);
infcx.set_tainted_by_errors(guar);
}
MirTypeckResults {
constraints,
universal_region_relations,

View file

@ -217,7 +217,7 @@ struct UniversalRegionIndices<'tcx> {
/// Whether we've encountered an error region. If we have, cancel all
/// outlives errors, as they are likely bogus.
pub tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
pub encountered_re_error: Cell<Option<ErrorGuaranteed>>,
}
#[derive(Debug, PartialEq)]
@ -442,8 +442,8 @@ impl<'tcx> UniversalRegions<'tcx> {
self.fr_fn_body
}
pub(crate) fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
self.indices.tainted_by_errors.get()
pub(crate) fn encountered_re_error(&self) -> Option<ErrorGuaranteed> {
self.indices.encountered_re_error.get()
}
}
@ -706,7 +706,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
UniversalRegionIndices {
indices: global_mapping.chain(arg_mapping).collect(),
fr_static,
tainted_by_errors: Cell::new(None),
encountered_re_error: Cell::new(None),
}
}
@ -916,7 +916,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
match r.kind() {
ty::ReVar(..) => r.as_var(),
ty::ReError(guar) => {
self.tainted_by_errors.set(Some(guar));
self.encountered_re_error.set(Some(guar));
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
// errors are being emitted and 2) it leaves the happy path unaffected.