@@ -219,38 +219,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
219
219
/// - returns basic blocks in a postorder,
220
220
/// - traverses the `BasicBlocks` CFG cache's reverse postorder backwards, and does not cache the
221
221
/// postorder itself.
222
- pub fn postorder < ' a , ' tcx > ( body : & ' a Body < ' tcx > ) -> PostorderIter < ' a , ' tcx > {
223
- let blocks = body. basic_blocks . reverse_postorder ( ) ;
224
- let len = blocks. len ( ) ;
225
- PostorderIter { body, blocks, idx : len }
226
- }
227
-
228
- #[ derive( Clone ) ]
229
- pub struct PostorderIter < ' a , ' tcx > {
222
+ pub fn postorder < ' a , ' tcx > (
230
223
body : & ' a Body < ' tcx > ,
231
- blocks : & ' a [ BasicBlock ] ,
232
- idx : usize ,
224
+ ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator + DoubleEndedIterator
225
+ {
226
+ reverse_postorder ( body) . rev ( )
233
227
}
234
228
235
- impl < ' a , ' tcx > Iterator for PostorderIter < ' a , ' tcx > {
236
- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
237
-
238
- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
239
- if self . idx == 0 {
240
- return None ;
241
- }
242
- self . idx -= 1 ;
243
-
244
- self . blocks . get ( self . idx ) . map ( |& bb| ( bb, & self . body [ bb] ) )
245
- }
246
-
247
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
248
- ( self . idx , Some ( self . idx ) )
249
- }
250
- }
251
-
252
- impl < ' a , ' tcx > ExactSizeIterator for PostorderIter < ' a , ' tcx > { }
253
-
254
229
/// Reverse postorder traversal of a graph
255
230
///
256
231
/// Reverse postorder is the reverse order of a postorder traversal.
@@ -332,6 +307,7 @@ pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> {
332
307
/// - makes use of the `BasicBlocks` CFG cache's reverse postorder.
333
308
pub fn reverse_postorder < ' a , ' tcx > (
334
309
body : & ' a Body < ' tcx > ,
335
- ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator {
310
+ ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator + DoubleEndedIterator
311
+ {
336
312
body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
337
313
}
0 commit comments