rustdoc: Make strip_hidden use a dedicated hidden item if any.

fixes #13806.
This commit is contained in:
Kang Seonghoon 2014-04-29 03:59:48 +09:00
parent 3e284eeb21
commit 3b5d6b4de5
2 changed files with 32 additions and 16 deletions

View File

@ -152,6 +152,21 @@ impl Item {
return None; return None;
} }
pub fn is_hidden_from_doc(&self) -> bool {
match self.doc_list() {
Some(ref l) => {
for innerattr in l.iter() {
match *innerattr {
Word(ref s) if "hidden" == *s => return true,
_ => (),
}
}
},
None => ()
}
return false;
}
pub fn is_mod(&self) -> bool { pub fn is_mod(&self) -> bool {
match self.inner { ModuleItem(..) => true, _ => false } match self.inner { ModuleItem(..) => true, _ => false }
} }
@ -736,7 +751,7 @@ impl Clean<Type> for ast::Ty {
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub enum StructField { pub enum StructField {
HiddenStructField, HiddenStructField, // inserted later by strip passes
TypedStructField(Type), TypedStructField(Type),
} }

View File

@ -33,23 +33,24 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
}; };
impl<'a> fold::DocFolder for Stripper<'a> { impl<'a> fold::DocFolder for Stripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() { if i.is_hidden_from_doc() {
match attr { debug!("found one in strip_hidden; removing");
&clean::List(ref x, ref l) if "doc" == *x => { self.stripped.insert(i.id);
for innerattr in l.iter() {
match innerattr { // use a dedicated hidden item for given item type if any
&clean::Word(ref s) if "hidden" == *s => { match i.inner {
debug!("found one in strip_hidden; removing"); clean::StructFieldItem(..) => {
self.stripped.insert(i.id); return Some(clean::Item {
return None; inner: clean::StructFieldItem(clean::HiddenStructField),
}, ..i
_ => (), });
} }
} _ => {
}, return None;
_ => () }
} }
} }
self.fold_item_recur(i) self.fold_item_recur(i)
} }
} }