88/// and could be improved in the future. This is mostly good enough for
99/// coherence right now and was annoying to implement, so I am leaving it
1010/// as is until we start using it for something else.
11- use std:: ops:: ControlFlow ;
12-
1311use rustc_infer:: infer:: InferCtxt ;
1412use rustc_middle:: traits:: query:: NoSolution ;
1513use rustc_middle:: traits:: solve:: { inspect, QueryResult } ;
1614use rustc_middle:: traits:: solve:: { Certainty , Goal } ;
1715use rustc_middle:: ty;
16+ use rustc_type_ir:: try_visit;
17+ use rustc_type_ir:: visit:: VisitorResult ;
1818
1919use crate :: solve:: inspect:: ProofTreeBuilder ;
2020use crate :: solve:: { GenerateProofTree , InferCtxtEvalExt } ;
@@ -53,10 +53,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
5353 /// to also use it to compute the most relevant goal
5454 /// for fulfillment errors. Will do that once we actually
5555 /// need it.
56- pub fn visit_nested < V : ProofTreeVisitor < ' tcx > > (
57- & self ,
58- visitor : & mut V ,
59- ) -> ControlFlow < V :: BreakTy > {
56+ pub fn visit_nested < V : ProofTreeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> V :: Result {
6057 // HACK: An arbitrary cutoff to avoid dealing with overflow and cycles.
6158 if self . goal . depth <= 10 {
6259 let infcx = self . goal . infcx ;
@@ -75,7 +72,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
7572 "unexpected failure when instantiating {:?}: {:?}" ,
7673 goal, self . nested_goals
7774 ) ;
78- return ControlFlow :: Continue ( ( ) ) ;
75+ return V :: Result :: output ( ) ;
7976 }
8077 } ;
8178 instantiated_goals. push ( goal) ;
@@ -84,17 +81,18 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
8481 for & goal in & instantiated_goals {
8582 let ( _, proof_tree) = infcx. evaluate_root_goal ( goal, GenerateProofTree :: Yes ) ;
8683 let proof_tree = proof_tree. unwrap ( ) ;
87- visitor. visit_goal ( & InspectGoal :: new (
84+ try_visit ! ( visitor. visit_goal( & InspectGoal :: new(
8885 infcx,
8986 self . goal. depth + 1 ,
9087 & proof_tree,
91- ) ) ? ;
88+ ) ) ) ;
9289 }
9390
94- ControlFlow :: Continue ( ( ) )
95- } ) ?;
91+ V :: Result :: output ( )
92+ } )
93+ } else {
94+ V :: Result :: output ( )
9695 }
97- ControlFlow :: Continue ( ( ) )
9896 }
9997}
10098
@@ -211,9 +209,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
211209
212210/// The public API to interact with proof trees.
213211pub trait ProofTreeVisitor < ' tcx > {
214- type BreakTy ;
212+ type Result : VisitorResult = ( ) ;
215213
216- fn visit_goal ( & mut self , goal : & InspectGoal < ' _ , ' tcx > ) -> ControlFlow < Self :: BreakTy > ;
214+ fn visit_goal ( & mut self , goal : & InspectGoal < ' _ , ' tcx > ) -> Self :: Result ;
217215}
218216
219217#[ extension( pub trait ProofTreeInferCtxtExt <' tcx>) ]
@@ -222,7 +220,7 @@ impl<'tcx> InferCtxt<'tcx> {
222220 & self ,
223221 goal : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
224222 visitor : & mut V ,
225- ) -> ControlFlow < V :: BreakTy > {
223+ ) -> V :: Result {
226224 self . probe ( |_| {
227225 let ( _, proof_tree) = self . evaluate_root_goal ( goal, GenerateProofTree :: Yes ) ;
228226 let proof_tree = proof_tree. unwrap ( ) ;
0 commit comments