Skip to content

Commit 8072811

Browse files
committed
Auto merge of #142085 - compiler-errors:perf-self-obl, r=lcnr
Don't walk into `Certainty::Yes` goals Don't walk into `Certainty::Yes` goals in the pending obligation finding code, since they will not have been stalled on an infer var anyways
2 parents 0b65d0d + db1ceca commit 8072811

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
44
use rustc_middle::traits::solve::GoalSource;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
7+
use rustc_trait_selection::solve::Certainty;
78
use rustc_trait_selection::solve::inspect::{
89
InspectConfig, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor,
910
};
@@ -117,6 +118,20 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'a, 'tcx> {
117118
}
118119

119120
fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) {
121+
// No need to walk into goal subtrees that certainly hold, since they
122+
// wouldn't then be stalled on an infer var.
123+
// FIXME: We also walk into normalizes-to goals since their certainty
124+
// is forced to `Certainty::Yes` since they pass down ambiguous subgoals
125+
// to their parent.
126+
if inspect_goal.result() == Ok(Certainty::Yes)
127+
&& !matches!(
128+
inspect_goal.goal().predicate.kind().skip_binder(),
129+
ty::PredicateKind::NormalizesTo(_)
130+
)
131+
{
132+
return;
133+
}
134+
120135
let tcx = self.fcx.tcx;
121136
let goal = inspect_goal.goal();
122137
if self.fcx.predicate_has_self_ty(goal.predicate, self.self_ty)

0 commit comments

Comments
 (0)