rust/src/librustdoc/fold.rs

103 lines
3.6 KiB
Rust
Raw Permalink Normal View History

2019-02-23 08:40:07 +01:00
use crate::clean::*;
crate struct StripItem(pub Item);
2018-07-22 23:01:09 +02:00
impl StripItem {
crate fn strip(self) -> Item {
2018-07-22 23:01:09 +02:00
match self.0 {
Item { kind: box StrippedItem(..), .. } => self.0,
2018-07-22 23:01:09 +02:00
mut i => {
i.kind = box StrippedItem(i.kind);
i
}
}
}
}
crate trait DocFolder: Sized {
fn fold_item(&mut self, item: Item) -> Option<Item> {
Some(self.fold_item_recur(item))
}
/// don't override!
fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind {
match kind {
StrippedItem(..) => unreachable!(),
2019-12-22 23:42:04 +01:00
ModuleItem(i) => ModuleItem(self.fold_mod(i)),
StructItem(mut i) => {
2016-02-28 16:38:51 +01:00
let num_fields = i.fields.len();
i.fields = i.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
2019-12-22 23:42:04 +01:00
i.fields_stripped |=
num_fields != i.fields.len() || i.fields.iter().any(|f| f.is_stripped());
StructItem(i)
2019-12-22 23:42:04 +01:00
}
2016-08-10 20:00:17 +02:00
UnionItem(mut i) => {
let num_fields = i.fields.len();
i.fields = i.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
2019-12-22 23:42:04 +01:00
i.fields_stripped |=
num_fields != i.fields.len() || i.fields.iter().any(|f| f.is_stripped());
2016-08-10 20:00:17 +02:00
UnionItem(i)
2019-12-22 23:42:04 +01:00
}
EnumItem(mut i) => {
2016-02-28 16:38:51 +01:00
let num_variants = i.variants.len();
i.variants = i.variants.into_iter().filter_map(|x| self.fold_item(x)).collect();
2019-12-22 23:42:04 +01:00
i.variants_stripped |=
num_variants != i.variants.len() || i.variants.iter().any(|f| f.is_stripped());
EnumItem(i)
2019-12-22 23:42:04 +01:00
}
TraitItem(mut i) => {
2016-02-28 16:38:51 +01:00
i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect();
TraitItem(i)
2019-12-22 23:42:04 +01:00
}
ImplItem(mut i) => {
2016-02-28 16:38:51 +01:00
i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect();
ImplItem(i)
2019-12-22 23:42:04 +01:00
}
VariantItem(i) => {
let i2 = i.clone(); // this clone is small
match i {
Variant::Struct(mut j) => {
2016-02-28 16:38:51 +01:00
let num_fields = j.fields.len();
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
2019-12-22 23:42:04 +01:00
j.fields_stripped |= num_fields != j.fields.len()
|| j.fields.iter().any(|f| f.is_stripped());
VariantItem(Variant::Struct(j))
2019-12-22 23:42:04 +01:00
}
_ => VariantItem(i2),
}
2019-12-22 23:42:04 +01:00
}
x => x,
}
}
/// don't override!
fn fold_item_recur(&mut self, mut item: Item) -> Item {
item.kind = box match *item.kind {
StrippedItem(box i) => StrippedItem(box self.fold_inner_recur(i)),
_ => self.fold_inner_recur(*item.kind),
};
item
}
fn fold_mod(&mut self, m: Module) -> Module {
Module {
is_crate: m.is_crate,
2019-12-22 23:42:04 +01:00
items: m.items.into_iter().filter_map(|i| self.fold_item(i)).collect(),
}
}
fn fold_crate(&mut self, mut c: Crate) -> Crate {
Upgrade to LLVM's master branch (LLVM 7) This commit upgrades the main LLVM submodule to LLVM's current master branch. The LLD submodule is updated in tandem as well as compiler-builtins. Along the way support was also added for LLVM 7's new features. This primarily includes the support for custom section concatenation natively in LLD so we now add wasm custom sections in LLVM IR rather than having custom support in rustc itself for doing so. Some other miscellaneous changes are: * We now pass `--gc-sections` to `wasm-ld` * The optimization level is now passed to `wasm-ld` * A `--stack-first` option is passed to LLD to have stack overflow always cause a trap instead of corrupting static data * The wasm target for LLVM switched to `wasm32-unknown-unknown`. * The syntax for aligned pointers has changed in LLVM IR and tests are updated to reflect this. * The `thumbv6m-none-eabi` target is disabled due to an [LLVM bug][llbug] Nowadays we've been mostly only upgrading whenever there's a major release of LLVM but enough changes have been happening on the wasm target that there's been growing motivation for quite some time now to upgrade out version of LLD. To upgrade LLD, however, we need to upgrade LLVM to avoid needing to build yet another version of LLVM on the builders. The revision of LLVM in use here is arbitrarily chosen. We will likely need to continue to update it over time if and when we discover bugs. Once LLVM 7 is fully released we can switch to that channel as well. [llbug]: https://bugs.llvm.org/show_bug.cgi?id=37382
2018-06-01 19:20:00 +02:00
c.module = c.module.take().and_then(|module| self.fold_item(module));
{
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
for (k, mut v) in external_traits {
v.trait_.items =
v.trait_.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
c.external_traits.borrow_mut().insert(k, v);
}
}
2016-02-28 16:38:51 +01:00
c
2012-09-19 23:37:43 +02:00
}
}