rustdoc: Strip impls of traits on #[doc(hidden)] types

In the strip-hidden pass, record all types that were stripped, and make
a second pass stripping all impls of traits for these types.
This commit is contained in:
Kevin Ballard 2014-02-11 14:42:23 -08:00
parent 52a3d38796
commit 9e6c3f03bc

View File

@ -22,30 +22,62 @@ use fold::DocFolder;
/// Strip items marked `#[doc(hidden)]`
pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
struct Stripper;
impl fold::DocFolder for Stripper {
fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() {
match attr {
&clean::List(~"doc", ref l) => {
for innerattr in l.iter() {
match innerattr {
&clean::Word(ref s) if "hidden" == *s => {
debug!("found one in strip_hidden; removing");
return None;
},
_ => (),
let mut stripped = HashSet::new();
// strip all #[doc(hidden)] items
let krate = {
struct Stripper<'a> {
stripped: &'a mut HashSet<ast::NodeId>
};
impl<'a> fold::DocFolder for Stripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() {
match attr {
&clean::List(~"doc", ref l) => {
for innerattr in l.iter() {
match innerattr {
&clean::Word(ref s) if "hidden" == *s => {
debug!("found one in strip_hidden; removing");
self.stripped.insert(i.id);
return None;
},
_ => (),
}
}
}
},
_ => ()
},
_ => ()
}
}
self.fold_item_recur(i)
}
self.fold_item_recur(i)
}
}
let mut stripper = Stripper;
let krate = stripper.fold_crate(krate);
let mut stripper = Stripper{ stripped: &mut stripped };
stripper.fold_crate(krate)
};
// strip any traits implemented on stripped items
let krate = {
struct ImplStripper<'a> {
stripped: &'a mut HashSet<ast::NodeId>
};
impl<'a> fold::DocFolder for ImplStripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
match i.inner {
clean::ImplItem(clean::Impl{ for_: clean::ResolvedPath{ id: for_id, .. },
.. }) => {
if self.stripped.contains(&for_id) {
return None;
}
}
_ => {}
}
self.fold_item_recur(i)
}
}
let mut stripper = ImplStripper{ stripped: &mut stripped };
stripper.fold_crate(krate)
};
(krate, None)
}