Skip to content

Commit 8b95291

Browse files
committed
borrowck: move error tainting earlier
1 parent 2886b36 commit 8b95291

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,11 @@ pub(crate) fn compute_sccs_applying_placeholder_outlives_constraints<'tcx>(
216216
placeholder_index_to_region: _,
217217
liveness_constraints,
218218
mut outlives_constraints,
219-
mut member_constraints,
219+
member_constraints,
220220
universe_causes,
221221
type_tests,
222222
} = constraints;
223223

224-
if let Some(guar) = universal_regions.tainted_by_errors() {
225-
debug!("Universal regions tainted by errors; removing constraints!");
226-
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
227-
// outlives bounds that we may end up checking.
228-
outlives_constraints = Default::default();
229-
member_constraints = Default::default();
230-
231-
// Also taint the entire scope.
232-
infcx.set_tainted_by_errors(guar);
233-
}
234-
235224
let fr_static = universal_regions.fr_static;
236225
let compute_sccs =
237226
|constraints: &OutlivesConstraintSet<'tcx>,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ pub(crate) fn type_check<'tcx>(
182182
)
183183
});
184184

185+
// In case type check encountered an error region, we suppress unhelpful extra
186+
// errors in by clearing out all outlives bounds that we may end up checking.
187+
if let Some(guar) = universal_region_relations.universal_regions.encountered_re_error() {
188+
debug!("encountered an error region; removing constraints!");
189+
constraints.outlives_constraints = Default::default();
190+
constraints.member_constraints = Default::default();
191+
constraints.type_tests = Default::default();
192+
root_cx.set_tainted_by_errors(guar);
193+
infcx.set_tainted_by_errors(guar);
194+
}
195+
185196
MirTypeckResults {
186197
constraints,
187198
universal_region_relations,

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ struct UniversalRegionIndices<'tcx> {
217217

218218
/// Whether we've encountered an error region. If we have, cancel all
219219
/// outlives errors, as they are likely bogus.
220-
pub tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
220+
pub encountered_re_error: Cell<Option<ErrorGuaranteed>>,
221221
}
222222

223223
#[derive(Debug, PartialEq)]
@@ -442,8 +442,8 @@ impl<'tcx> UniversalRegions<'tcx> {
442442
self.fr_fn_body
443443
}
444444

445-
pub(crate) fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
446-
self.indices.tainted_by_errors.get()
445+
pub(crate) fn encountered_re_error(&self) -> Option<ErrorGuaranteed> {
446+
self.indices.encountered_re_error.get()
447447
}
448448
}
449449

@@ -706,7 +706,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
706706
UniversalRegionIndices {
707707
indices: global_mapping.chain(arg_mapping).collect(),
708708
fr_static,
709-
tainted_by_errors: Cell::new(None),
709+
encountered_re_error: Cell::new(None),
710710
}
711711
}
712712

@@ -916,7 +916,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
916916
match r.kind() {
917917
ty::ReVar(..) => r.as_var(),
918918
ty::ReError(guar) => {
919-
self.tainted_by_errors.set(Some(guar));
919+
self.encountered_re_error.set(Some(guar));
920920
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
921921
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
922922
// errors are being emitted and 2) it leaves the happy path unaffected.

0 commit comments

Comments
 (0)