diff options
| author | bors <bors@rust-lang.org> | 2025-06-08 05:30:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-08 05:30:59 +0000 |
| commit | 8072811356a178dbdf8ca09b1635cfafd4661971 (patch) | |
| tree | 0a27d1494826bf3dfa0a239db52994ffbbba096b | |
| parent | 0b65d0db5f77c44bf37b4a25489562d68c14aecf (diff) | |
| parent | db1cecaacc9c8ac7716a2ee86733d9a3daf089ef (diff) | |
| download | rust-8072811356a178dbdf8ca09b1635cfafd4661971.tar.gz rust-8072811356a178dbdf8ca09b1635cfafd4661971.zip | |
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
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs index e068e607902..7f1f3c3c802 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs @@ -4,6 +4,7 @@ use rustc_infer::traits::{self, ObligationCause, PredicateObligations}; use rustc_middle::traits::solve::GoalSource; use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_span::Span; +use rustc_trait_selection::solve::Certainty; use rustc_trait_selection::solve::inspect::{ InspectConfig, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor, }; @@ -117,6 +118,20 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'a, 'tcx> { } fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) { + // No need to walk into goal subtrees that certainly hold, since they + // wouldn't then be stalled on an infer var. + // FIXME: We also walk into normalizes-to goals since their certainty + // is forced to `Certainty::Yes` since they pass down ambiguous subgoals + // to their parent. + if inspect_goal.result() == Ok(Certainty::Yes) + && !matches!( + inspect_goal.goal().predicate.kind().skip_binder(), + ty::PredicateKind::NormalizesTo(_) + ) + { + return; + } + let tcx = self.fcx.tcx; let goal = inspect_goal.goal(); if self.fcx.predicate_has_self_ty(goal.predicate, self.self_ty) |
