@@ -219,38 +219,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
219219/// - returns basic blocks in a postorder,
220220/// - traverses the `BasicBlocks` CFG cache's reverse postorder backwards, and does not cache the
221221/// 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 > (
230223 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 ( )
233227}
234228
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-
254229/// Reverse postorder traversal of a graph
255230///
256231/// Reverse postorder is the reverse order of a postorder traversal.
@@ -332,6 +307,7 @@ pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> {
332307/// - makes use of the `BasicBlocks` CFG cache's reverse postorder.
333308pub fn reverse_postorder < ' a , ' tcx > (
334309 body : & ' a Body < ' tcx > ,
335- ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator {
310+ ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator + DoubleEndedIterator
311+ {
336312 body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
337313}
0 commit comments