Skip to content

Commit 931a3a6

Browse files
committed
Re-use the fresh InferCtxt
1 parent 04964d7 commit 931a3a6

File tree

1 file changed

+22
-22
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+22
-22
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -947,32 +947,32 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
947947

948948
let tcx = selcx.infcx().tcx;
949949

950-
result.obligations.drain_filter(|projected_obligation| {
951-
// If any global obligations always apply, considering regions, then we don't
952-
// need to include them. The `is_global` check rules out inference variables,
953-
// so there's no need for the caller of `opt_normalize_projection_type`
954-
// to evaluate them.
955-
// Note that we do *not* discard obligations that evaluate to
956-
// `EvaluatedtoOkModuloRegions`. Evaluating these obligations
957-
// inside of a query (e.g. `evaluate_obligation`) can change
958-
// the result to `EvaluatedToOkModuloRegions`, while an
959-
// `EvaluatedToOk` obligation will never change the result.
960-
// See #85360 for more details
961-
if !projected_obligation.is_global(tcx) {
962-
return false;
963-
}
964-
965-
// We create a fresh `InferCtxt` for each predicate we speculatively evaluate,
966-
// so that we won't create (and cache) any spurious projection cycles in the main
967-
// `InferCtxt`
968-
tcx.infer_ctxt().enter(|infcx| {
969-
let mut canonical =
970-
SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
950+
// We create a fresh `InferCtxt` for speculative evaluation
951+
// so that we won't create (and cache) any spurious projection cycles in the main
952+
// `InferCtxt`
953+
tcx.infer_ctxt().enter(|infcx| {
954+
let mut canonical =
955+
SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
956+
957+
result.obligations.drain_filter(|projected_obligation| {
958+
// If any global obligations always apply, considering regions, then we don't
959+
// need to include them. The `is_global` check rules out inference variables,
960+
// so there's no need for the caller of `opt_normalize_projection_type`
961+
// to evaluate them.
962+
// Note that we do *not* discard obligations that evaluate to
963+
// `EvaluatedtoOkModuloRegions`. Evaluating these obligations
964+
// inside of a query (e.g. `evaluate_obligation`) can change
965+
// the result to `EvaluatedToOkModuloRegions`, while an
966+
// `EvaluatedToOk` obligation will never change the result.
967+
// See #85360 for more details
968+
if !projected_obligation.is_global(tcx) {
969+
return false;
970+
}
971971

972972
canonical
973973
.evaluate_root_obligation(projected_obligation)
974974
.map_or(false, |res| res.must_apply_considering_regions())
975-
})
975+
});
976976
});
977977

978978
if use_cache {

0 commit comments

Comments
 (0)