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};
20 use passes::{ImplStripper, Pass};
22 pub const STRIP_HIDDEN: Pass =
23 Pass::early("strip-hidden", strip_hidden,
24 "strips all doc(hidden) items from the output");
26 /// Strip items marked `#[doc(hidden)]`
27 pub fn strip_hidden(krate: clean::Crate, _: &DocContext) -> clean::Crate {
28 let mut retained = DefIdSet();
30 // strip all #[doc(hidden)] items
32 let mut stripper = Stripper{ retained: &mut retained, update_retained: true };
33 stripper.fold_crate(krate)
36 // strip all impls referencing stripped items
37 let mut stripper = ImplStripper { retained: &retained };
38 stripper.fold_crate(krate)
42 retained: &'a mut DefIdSet,
43 update_retained: bool,
46 impl<'a> fold::DocFolder for Stripper<'a> {
47 fn fold_item(&mut self, i: Item) -> Option<Item> {
48 if i.attrs.lists("doc").has_word("hidden") {
49 debug!("found one in strip_hidden; removing");
50 // use a dedicated hidden item for given item type if any
52 clean::StructFieldItem(..) | clean::ModuleItem(..) => {
53 // We need to recurse into stripped modules to
54 // strip things like impl methods but when doing so
55 // we must not add any items to the `retained` set.
56 let old = mem::replace(&mut self.update_retained, false);
57 let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
58 self.update_retained = old;
64 if self.update_retained {
65 self.retained.insert(i.def_id);
68 self.fold_item_recur(i)