File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -658,7 +658,7 @@ pub fn expr_if(
658658 } ;
659659 expr_from_text ( & format ! ( "if {condition} {then_branch} {else_branch}" ) )
660660}
661- pub fn expr_for_loop ( pat : ast:: Pat , expr : ast:: Expr , block : ast:: BlockExpr ) -> ast:: Expr {
661+ pub fn expr_for_loop ( pat : ast:: Pat , expr : ast:: Expr , block : ast:: BlockExpr ) -> ast:: ForExpr {
662662 expr_from_text ( & format ! ( "for {pat} in {expr} {block}" ) )
663663}
664664
Original file line number Diff line number Diff line change @@ -671,6 +671,26 @@ impl SyntaxFactory {
671671 ast
672672 }
673673
674+ pub fn expr_for_loop (
675+ & self ,
676+ pat : ast:: Pat ,
677+ iterable : ast:: Expr ,
678+ body : ast:: BlockExpr ,
679+ ) -> ast:: ForExpr {
680+ let ast =
681+ make:: expr_for_loop ( pat. clone ( ) , iterable. clone ( ) , body. clone ( ) ) . clone_for_update ( ) ;
682+
683+ if let Some ( mut mapping) = self . mappings ( ) {
684+ let mut builder = SyntaxMappingBuilder :: new ( ast. syntax ( ) . clone ( ) ) ;
685+ builder. map_node ( pat. syntax ( ) . clone ( ) , ast. pat ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
686+ builder. map_node ( iterable. syntax ( ) . clone ( ) , ast. iterable ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
687+ builder. map_node ( body. syntax ( ) . clone ( ) , ast. loop_body ( ) . unwrap ( ) . syntax ( ) . clone ( ) ) ;
688+ builder. finish ( & mut mapping) ;
689+ }
690+
691+ ast
692+ }
693+
674694 pub fn expr_let ( & self , pattern : ast:: Pat , expr : ast:: Expr ) -> ast:: LetExpr {
675695 let ast = make:: expr_let ( pattern. clone ( ) , expr. clone ( ) ) . clone_for_update ( ) ;
676696
You can’t perform that action at this time.
0 commit comments