about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-04 22:49:45 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-13 05:11:51 +0000
commit60440b226d2f70bdae803443ff7ad2e2af2c9b10 (patch)
tree03240ec5ae54c778f56f42cc9a43524c8bfc752d /src/libsyntax
parent50f94f6c95c944f08c4af264f48260e42efefd47 (diff)
downloadrust-60440b226d2f70bdae803443ff7ad2e2af2c9b10.tar.gz
rust-60440b226d2f70bdae803443ff7ad2e2af2c9b10.zip
Refactor `noop_fold_stmt_kind` out of `noop_fold_stmt`.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/fold.rs50
1 files changed, 13 insertions, 37 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 7500bfe9caa..9fb4d0203f4 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -1320,51 +1320,27 @@ pub fn noop_fold_exprs<T: Folder>(es: Vec<P<Expr>>, folder: &mut T) -> Vec<P<Exp
     es.move_flat_map(|e| folder.fold_opt_expr(e))
 }
 
-pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T)
-                                 -> SmallVector<Stmt> {
+pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVector<Stmt> {
     let id = folder.new_id(id);
     let span = folder.new_span(span);
+    noop_fold_stmt_kind(node, folder).into_iter().map(|node| {
+        Stmt { id: id, node: node, span: span }
+    }).collect()
+}
 
+pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVector<StmtKind> {
     match node {
-        StmtKind::Local(local) => SmallVector::one(Stmt {
-            id: id,
-            node: StmtKind::Local(folder.fold_local(local)),
-            span: span,
-        }),
-        StmtKind::Item(item) => folder.fold_item(item).into_iter().map(|item| Stmt {
-            id: id,
-            node: StmtKind::Item(item),
-            span: span,
-        }).collect(),
+        StmtKind::Local(local) => SmallVector::one(StmtKind::Local(folder.fold_local(local))),
+        StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),
         StmtKind::Expr(expr) => {
-            if let Some(expr) = folder.fold_opt_expr(expr) {
-                SmallVector::one(Stmt {
-                    id: id,
-                    node: StmtKind::Expr(expr),
-                    span: span,
-                })
-            } else {
-                SmallVector::zero()
-            }
+            folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect()
         }
         StmtKind::Semi(expr) => {
-            if let Some(expr) = folder.fold_opt_expr(expr) {
-                SmallVector::one(Stmt {
-                    id: id,
-                    node: StmtKind::Semi(expr),
-                    span: span,
-                })
-            } else {
-                SmallVector::zero()
-            }
+            folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect()
         }
-        StmtKind::Mac(mac) => SmallVector::one(Stmt {
-            id: id,
-            node: StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
-                (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
-            })),
-            span: span,
-        })
+        StmtKind::Mac(mac) => SmallVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
+            (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
+        }))),
     }
 }