From 3b5d6b4de54cfce8a1897faa8eadb49a2a1d0688 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Tue, 29 Apr 2014 03:59:48 +0900 Subject: [PATCH] rustdoc: Make strip_hidden use a dedicated hidden item if any. fixes #13806. --- src/librustdoc/clean.rs | 17 ++++++++++++++++- src/librustdoc/passes.rs | 31 ++++++++++++++++--------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index cabfb05cb6f..cabfe695df7 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -152,6 +152,21 @@ impl Item { 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 { match self.inner { ModuleItem(..) => true, _ => false } } @@ -736,7 +751,7 @@ impl Clean for ast::Ty { #[deriving(Clone, Encodable, Decodable)] pub enum StructField { - HiddenStructField, + HiddenStructField, // inserted later by strip passes TypedStructField(Type), } diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 9b6d04f2ca4..f8a2382c028 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -33,23 +33,24 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { }; impl<'a> fold::DocFolder for Stripper<'a> { fn fold_item(&mut self, i: Item) -> Option { - for attr in i.attrs.iter() { - match attr { - &clean::List(ref x, ref l) if "doc" == *x => { - 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; - }, - _ => (), - } - } - }, - _ => () + if i.is_hidden_from_doc() { + debug!("found one in strip_hidden; removing"); + self.stripped.insert(i.id); + + // use a dedicated hidden item for given item type if any + match i.inner { + clean::StructFieldItem(..) => { + return Some(clean::Item { + inner: clean::StructFieldItem(clean::HiddenStructField), + ..i + }); + } + _ => { + return None; + } } } + self.fold_item_recur(i) } }