From 7e77d19905ebfcc76c19301587baf2c53acf2fd9 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Thu, 2 Aug 2018 16:24:20 -0500 Subject: [PATCH] preserve order if blocks are between items --- src/librustc_driver/pretty.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 2777593b6bd..9135c9e179f 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -798,17 +798,17 @@ fn block_to_stmt(b: ast::Block, sess: &Session) -> ast::Stmt { fold::noop_fold_block(b, self) } else { b.map(|b| { - let old_blocks = self.nested_blocks.replace(vec![]); + let mut stmts = vec![]; + for s in b.stmts { + let old_blocks = self.nested_blocks.replace(vec![]); - let mut stmts = b.stmts.into_iter() - .flat_map(|s| self.fold_stmt(s)) - .filter(|s| s.is_item()) - .collect::>(); + stmts.extend(self.fold_stmt(s).into_iter().filter(|s| s.is_item())); - // we put a Some in there earlier with that replace(), so this is valid - let new_blocks = self.nested_blocks.take().unwrap(); - self.nested_blocks = old_blocks; - stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, &self.sess))); + // we put a Some in there earlier with that replace(), so this is valid + let new_blocks = self.nested_blocks.take().unwrap(); + self.nested_blocks = old_blocks; + stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, &self.sess))); + } let mut new_block = ast::Block { stmts,