Skip to content

Commit 60440b2

Browse files
committed
Refactor noop_fold_stmt_kind out of noop_fold_stmt.
1 parent 50f94f6 commit 60440b2

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

src/libsyntax/fold.rs

+13-37
Original file line numberDiff line numberDiff line change
@@ -1320,51 +1320,27 @@ pub fn noop_fold_exprs<T: Folder>(es: Vec<P<Expr>>, folder: &mut T) -> Vec<P<Exp
13201320
es.move_flat_map(|e| folder.fold_opt_expr(e))
13211321
}
13221322

1323-
pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T)
1324-
-> SmallVector<Stmt> {
1323+
pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVector<Stmt> {
13251324
let id = folder.new_id(id);
13261325
let span = folder.new_span(span);
1326+
noop_fold_stmt_kind(node, folder).into_iter().map(|node| {
1327+
Stmt { id: id, node: node, span: span }
1328+
}).collect()
1329+
}
13271330

1331+
pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVector<StmtKind> {
13281332
match node {
1329-
StmtKind::Local(local) => SmallVector::one(Stmt {
1330-
id: id,
1331-
node: StmtKind::Local(folder.fold_local(local)),
1332-
span: span,
1333-
}),
1334-
StmtKind::Item(item) => folder.fold_item(item).into_iter().map(|item| Stmt {
1335-
id: id,
1336-
node: StmtKind::Item(item),
1337-
span: span,
1338-
}).collect(),
1333+
StmtKind::Local(local) => SmallVector::one(StmtKind::Local(folder.fold_local(local))),
1334+
StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),
13391335
StmtKind::Expr(expr) => {
1340-
if let Some(expr) = folder.fold_opt_expr(expr) {
1341-
SmallVector::one(Stmt {
1342-
id: id,
1343-
node: StmtKind::Expr(expr),
1344-
span: span,
1345-
})
1346-
} else {
1347-
SmallVector::zero()
1348-
}
1336+
folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect()
13491337
}
13501338
StmtKind::Semi(expr) => {
1351-
if let Some(expr) = folder.fold_opt_expr(expr) {
1352-
SmallVector::one(Stmt {
1353-
id: id,
1354-
node: StmtKind::Semi(expr),
1355-
span: span,
1356-
})
1357-
} else {
1358-
SmallVector::zero()
1359-
}
1339+
folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect()
13601340
}
1361-
StmtKind::Mac(mac) => SmallVector::one(Stmt {
1362-
id: id,
1363-
node: StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
1364-
(folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
1365-
})),
1366-
span: span,
1367-
})
1341+
StmtKind::Mac(mac) => SmallVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
1342+
(folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
1343+
}))),
13681344
}
13691345
}
13701346

0 commit comments

Comments
 (0)