Skip to content

Don't walk into Certainty::Yes goals #142085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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!(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently report nested goals as Certainty::Yes even if they had nested goals... we could/should fix that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizes-to goals?

in InspectGoal::new, we should also eagerly try to prove the nested goals if the normalizes_to_term_hack is Some 🤔

r=me with a FIXME here saying that normalizes-to nested goals are kinda scuffed or actually fix the impl in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizes-to goals?

Yes, typo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by #142127.

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)
Expand Down
Loading