File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -763,6 +763,10 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
763763}
764764
765765pub fn assign_node_ids ( sess : & Session , krate : ast:: Crate ) -> ast:: Crate {
766+ use syntax:: codemap:: Spanned ;
767+ use syntax:: ptr:: P ;
768+ use syntax:: util:: move_map:: MoveMap ;
769+
766770 struct NodeIdAssigner < ' a > {
767771 sess : & ' a Session ,
768772 }
@@ -772,6 +776,27 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
772776 assert_eq ! ( old_id, ast:: DUMMY_NODE_ID ) ;
773777 self . sess . next_node_id ( )
774778 }
779+
780+ fn fold_block ( & mut self , block : P < ast:: Block > ) -> P < ast:: Block > {
781+ block. map ( |mut block| {
782+ block. id = self . new_id ( block. id ) ;
783+
784+ let stmt = block. stmts . pop ( ) ;
785+ block. stmts = block. stmts . move_flat_map ( |s| self . fold_stmt ( s) . into_iter ( ) ) ;
786+ if let Some ( Spanned { node : ast:: StmtKind :: Expr ( expr, _) , span } ) = stmt {
787+ let expr = self . fold_expr ( expr) ;
788+ let id = expr. id ;
789+ block. stmts . push ( Spanned {
790+ span : span,
791+ node : ast:: StmtKind :: Expr ( expr, id)
792+ } ) ;
793+ } else if let Some ( stmt) = stmt {
794+ block. stmts . extend ( self . fold_stmt ( stmt) ) ;
795+ }
796+
797+ block
798+ } )
799+ }
775800 }
776801
777802 let krate = time ( sess. time_passes ( ) ,
You can’t perform that action at this time.
0 commit comments