@@ -203,26 +203,32 @@ where
203
203
return Poll :: Ready ( Ok ( v) ) ;
204
204
}
205
205
206
- let has_budget_now = coop:: has_budget_remaining ( ) ;
207
-
208
- let delay = me. delay ;
209
-
210
- let poll_delay = || -> Poll < Self :: Output > {
211
- match delay. poll ( cx) {
212
- Poll :: Ready ( ( ) ) => Poll :: Ready ( Err ( Elapsed :: new ( ) ) ) ,
213
- Poll :: Pending => Poll :: Pending ,
214
- }
215
- } ;
216
-
217
- if let ( true , false ) = ( had_budget_before, has_budget_now) {
218
- // if it is the underlying future that exhausted the budget, we poll
219
- // the `delay` with an unconstrained one. This prevents pathological
220
- // cases where the underlying future always exhausts the budget and
221
- // we never get a chance to evaluate whether the timeout was hit or
222
- // not.
223
- coop:: with_unconstrained ( poll_delay)
224
- } else {
225
- poll_delay ( )
226
- }
206
+ poll_delay ( had_budget_before, me. delay , cx) . map ( Err )
207
+ }
208
+ }
209
+
210
+ // The T-invariant portion of Timeout::<T>::poll. Pulling this out reduces the
211
+ // amount of code that gets duplicated during monomorphization.
212
+ fn poll_delay (
213
+ had_budget_before : bool ,
214
+ delay : Pin < & mut Sleep > ,
215
+ cx : & mut task:: Context < ' _ > ,
216
+ ) -> Poll < Elapsed > {
217
+ let delay_poll = || match delay. poll ( cx) {
218
+ Poll :: Ready ( ( ) ) => Poll :: Ready ( Elapsed :: new ( ) ) ,
219
+ Poll :: Pending => Poll :: Pending ,
220
+ } ;
221
+
222
+ let has_budget_now = coop:: has_budget_remaining ( ) ;
223
+
224
+ if let ( true , false ) = ( had_budget_before, has_budget_now) {
225
+ // if it is the underlying future that exhausted the budget, we poll
226
+ // the `delay` with an unconstrained one. This prevents pathological
227
+ // cases where the underlying future always exhausts the budget and
228
+ // we never get a chance to evaluate whether the timeout was hit or
229
+ // not.
230
+ coop:: with_unconstrained ( delay_poll)
231
+ } else {
232
+ delay_poll ( )
227
233
}
228
234
}
0 commit comments