@@ -50,36 +50,49 @@ impl OverflowData {
5050 }
5151}
5252
53- impl < ' tcx > SearchGraph < ' tcx > {
54- pub fn deal_with_overflow (
55- & mut self ,
56- tcx : TyCtxt < ' tcx > ,
57- goal : Canonical < ' tcx , impl Sized > ,
58- ) -> QueryResult < ' tcx > {
59- self . overflow_data . deal_with_overflow ( ) ;
60- response_no_constraints ( tcx, goal, Certainty :: Maybe ( MaybeCause :: Overflow ) )
61- }
62- }
53+ pub ( crate ) trait OverflowHandler < ' tcx > {
54+ fn search_graph ( & mut self ) -> & mut SearchGraph < ' tcx > ;
6355
64- impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
65- /// A `while`-loop which tracks overflow.
66- pub fn repeat_while_none < T > (
56+ fn repeat_while_none < T > (
6757 & mut self ,
68- mut overflow_body : impl FnMut ( & mut Self ) -> T ,
58+ on_overflow : impl FnOnce ( & mut Self ) -> T ,
6959 mut loop_body : impl FnMut ( & mut Self ) -> Option < Result < T , NoSolution > > ,
7060 ) -> Result < T , NoSolution > {
71- let start_depth = self . search_graph . overflow_data . additional_depth ;
72- let depth = self . search_graph . stack . len ( ) ;
73- while !self . search_graph . overflow_data . has_overflow ( depth) {
61+ let start_depth = self . search_graph ( ) . overflow_data . additional_depth ;
62+ let depth = self . search_graph ( ) . stack . len ( ) ;
63+ while !self . search_graph ( ) . overflow_data . has_overflow ( depth) {
7464 if let Some ( result) = loop_body ( self ) {
75- self . search_graph . overflow_data . additional_depth = start_depth;
65+ self . search_graph ( ) . overflow_data . additional_depth = start_depth;
7666 return result;
7767 }
7868
79- self . search_graph . overflow_data . additional_depth += 1 ;
69+ self . search_graph ( ) . overflow_data . additional_depth += 1 ;
8070 }
81- self . search_graph . overflow_data . additional_depth = start_depth;
82- self . search_graph . overflow_data . deal_with_overflow ( ) ;
83- Ok ( overflow_body ( self ) )
71+ self . search_graph ( ) . overflow_data . additional_depth = start_depth;
72+ self . search_graph ( ) . overflow_data . deal_with_overflow ( ) ;
73+ Ok ( on_overflow ( self ) )
74+ }
75+ }
76+
77+ impl < ' tcx > OverflowHandler < ' tcx > for EvalCtxt < ' _ , ' tcx > {
78+ fn search_graph ( & mut self ) -> & mut SearchGraph < ' tcx > {
79+ & mut self . search_graph
80+ }
81+ }
82+
83+ impl < ' tcx > OverflowHandler < ' tcx > for SearchGraph < ' tcx > {
84+ fn search_graph ( & mut self ) -> & mut SearchGraph < ' tcx > {
85+ self
86+ }
87+ }
88+
89+ impl < ' tcx > SearchGraph < ' tcx > {
90+ pub fn deal_with_overflow (
91+ & mut self ,
92+ tcx : TyCtxt < ' tcx > ,
93+ goal : Canonical < ' tcx , impl Sized > ,
94+ ) -> QueryResult < ' tcx > {
95+ self . overflow_data . deal_with_overflow ( ) ;
96+ response_no_constraints ( tcx, goal, Certainty :: Maybe ( MaybeCause :: Overflow ) )
8497 }
8598}
0 commit comments