From f6bfe283ddbd31a0cc91c50fe53ddbffd59f5884 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 2 May 2024 13:51:13 -0400 Subject: [PATCH] Super visitor --- compiler/rustc_trait_selection/src/solve/fulfill.rs | 13 ++++--------- .../src/solve/inspect/analyse.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index d4fde60fd4a72..8e1095e0353dd 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -219,14 +219,14 @@ fn fulfillment_error_for_no_solution<'tcx>( } ty::PredicateKind::Subtype(pred) => { let (a, b) = infcx.enter_forall_and_leak_universe( - root_obligation.predicate.kind().rebind((pred.a, pred.b)), + obligation.predicate.kind().rebind((pred.a, pred.b)), ); let expected_found = ExpectedFound::new(true, a, b); FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found)) } ty::PredicateKind::Coerce(pred) => { let (a, b) = infcx.enter_forall_and_leak_universe( - root_obligation.predicate.kind().rebind((pred.a, pred.b)), + obligation.predicate.kind().rebind((pred.a, pred.b)), ); let expected_found = ExpectedFound::new(false, a, b); FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found)) @@ -298,13 +298,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { } fn visit_goal(&mut self, goal: &super::inspect::InspectGoal<'_, 'tcx>) -> Self::Result { - let candidates = goal.candidates(); // FIXME: Throw out candidates that have no failing WC and >1 failing misc goal. - - // HACK: - if self.obligation.recursion_depth > 3 { - return ControlFlow::Break(self.obligation.clone()); - } + let candidates = goal.candidates(); let [candidate] = candidates.as_slice() else { return ControlFlow::Break(self.obligation.clone()); @@ -376,7 +371,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { recursion_depth: self_.obligation.recursion_depth + 1, } }, - |self_| self_.visit_goal(&nested_goal), + |self_| nested_goal.visit_with(self), )?; } diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index de6c2322e8d8d..70a52d9fe7f53 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -360,6 +360,14 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> { source, } } + + pub(crate) fn visit_with>(&self, visitor: &mut V) -> V::Result { + if self.goal.depth < visitor.config().max_depth { + try_visit!(visitor.visit_goal(self)); + } + + V::Result::output() + } } /// The public API to interact with proof trees.