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 let krate = stripper.fold_crate(krate);
44 retained: &'a mut DefIdSet,
45 update_retained: bool,
48 impl<'a> fold::DocFolder for Stripper<'a> {
49 fn fold_item(&mut self, i: Item) -> Option<Item> {
50 if i.attrs.lists("doc").has_word("hidden") {
51 debug!("strip_hidden: stripping {} {:?}", i.type_(), i.name);
52 // use a dedicated hidden item for given item type if any
54 clean::StructFieldItem(..) | clean::ModuleItem(..) => {
55 // We need to recurse into stripped modules to
56 // strip things like impl methods but when doing so
57 // we must not add any items to the `retained` set.
58 let old = mem::replace(&mut self.update_retained, false);
59 let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
60 self.update_retained = old;
66 if self.update_retained {
67 self.retained.insert(i.def_id);
70 self.fold_item_recur(i)