1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use rustc::util::nodemap::DefIdSet;
14 use clean::{self, AttributesExt, NestedAttributesExt};
19 use fold::FoldItem::Strip;
20 use passes::ImplStripper;
22 /// Strip items marked `#[doc(hidden)]`
23 pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
24 let mut retained = DefIdSet();
26 // strip all #[doc(hidden)] items
28 let mut stripper = Stripper{ retained: &mut retained, update_retained: true };
29 stripper.fold_crate(krate)
32 // strip all impls referencing stripped items
33 let mut stripper = ImplStripper { retained: &retained };
34 stripper.fold_crate(krate)
38 retained: &'a mut DefIdSet,
39 update_retained: bool,
42 impl<'a> fold::DocFolder for Stripper<'a> {
43 fn fold_item(&mut self, i: Item) -> Option<Item> {
44 if i.attrs.lists("doc").has_word("hidden") {
45 debug!("found one in strip_hidden; removing");
46 // use a dedicated hidden item for given item type if any
48 clean::StructFieldItem(..) | clean::ModuleItem(..) => {
49 // We need to recurse into stripped modules to
50 // strip things like impl methods but when doing so
51 // we must not add any items to the `retained` set.
52 let old = mem::replace(&mut self.update_retained, false);
53 let ret = Strip(self.fold_item_recur(i).unwrap()).fold();
54 self.update_retained = old;
60 if self.update_retained {
61 self.retained.insert(i.def_id);
64 self.fold_item_recur(i)