@@ -50,36 +50,49 @@ impl OverflowData {
50
50
}
51
51
}
52
52
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 > ;
63
55
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 > (
67
57
& mut self ,
68
- mut overflow_body : impl FnMut ( & mut Self ) -> T ,
58
+ on_overflow : impl FnOnce ( & mut Self ) -> T ,
69
59
mut loop_body : impl FnMut ( & mut Self ) -> Option < Result < T , NoSolution > > ,
70
60
) -> 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) {
74
64
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;
76
66
return result;
77
67
}
78
68
79
- self . search_graph . overflow_data . additional_depth += 1 ;
69
+ self . search_graph ( ) . overflow_data . additional_depth += 1 ;
80
70
}
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 ) )
84
97
}
85
98
}
0 commit comments