mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
front -- collapse iterator actions that require access to the same &mut state
This commit is contained in:
parent
ec6d122826
commit
7ffa67ce92
@ -58,8 +58,10 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
|
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
|
||||||
let filtered_items = m.items.iter()
|
let filtered_items: ~[&@ast::Item] = m.items.iter()
|
||||||
.filter(|&a| item_in_cfg(cx, *a))
|
.filter(|&a| item_in_cfg(cx, *a))
|
||||||
|
.collect();
|
||||||
|
let flattened_items = filtered_items.move_iter()
|
||||||
.flat_map(|&x| cx.fold_item(x).move_iter())
|
.flat_map(|&x| cx.fold_item(x).move_iter())
|
||||||
.collect();
|
.collect();
|
||||||
let filtered_view_items = m.view_items.iter().filter_map(|a| {
|
let filtered_view_items = m.view_items.iter().filter_map(|a| {
|
||||||
@ -67,7 +69,7 @@ fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
|
|||||||
}).collect();
|
}).collect();
|
||||||
ast::Mod {
|
ast::Mod {
|
||||||
view_items: filtered_view_items,
|
view_items: filtered_view_items,
|
||||||
items: filtered_items
|
items: flattened_items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,23 +115,26 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
|
|||||||
ast::ItemStruct(fold_struct(cx, def), generics.clone())
|
ast::ItemStruct(fold_struct(cx, def), generics.clone())
|
||||||
}
|
}
|
||||||
ast::ItemEnum(ref def, ref generics) => {
|
ast::ItemEnum(ref def, ref generics) => {
|
||||||
let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| {
|
let mut variants = def.variants.iter().map(|c| c.clone()).
|
||||||
(cx.in_cfg)(m.node.attrs)
|
filter_map(|v| {
|
||||||
}).map(|v| {
|
if !(cx.in_cfg)(v.node.attrs) {
|
||||||
match v.node.kind {
|
None
|
||||||
ast::TupleVariantKind(..) => v,
|
} else {
|
||||||
ast::StructVariantKind(def) => {
|
Some(match v.node.kind {
|
||||||
let def = fold_struct(cx, def);
|
ast::TupleVariantKind(..) => v,
|
||||||
@codemap::Spanned {
|
ast::StructVariantKind(def) => {
|
||||||
node: ast::Variant_ {
|
let def = fold_struct(cx, def);
|
||||||
kind: ast::StructVariantKind(def),
|
@codemap::Spanned {
|
||||||
..v.node.clone()
|
node: ast::Variant_ {
|
||||||
},
|
kind: ast::StructVariantKind(def),
|
||||||
..*v
|
..v.node.clone()
|
||||||
}
|
},
|
||||||
|
..*v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
ast::ItemEnum(ast::EnumDef {
|
ast::ItemEnum(ast::EnumDef {
|
||||||
variants: variants.collect(),
|
variants: variants.collect(),
|
||||||
}, generics.clone())
|
}, generics.clone())
|
||||||
@ -165,10 +170,11 @@ fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||||
let resulting_stmts = b.stmts.iter()
|
let resulting_stmts: ~[&@ast::Stmt] =
|
||||||
.filter(|&a| retain_stmt(cx, *a))
|
b.stmts.iter().filter(|&a| retain_stmt(cx, *a)).collect();
|
||||||
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
|
let resulting_stmts = resulting_stmts.move_iter()
|
||||||
.collect();
|
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
|
||||||
|
.collect();
|
||||||
let filtered_view_items = b.view_items.iter().filter_map(|a| {
|
let filtered_view_items = b.view_items.iter().filter_map(|a| {
|
||||||
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
|
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
|
||||||
}).collect();
|
}).collect();
|
||||||
|
Loading…
Reference in New Issue
Block a user