Skip to content

Commit 3cd6c1e

Browse files
committed
auto merge of #13827 : lifthrasiir/rust/rustdoc-hidden-pub-field, r=alexcrichton
Fixes #13806. Also adds a note to `HiddenStructField` about why it doesn't appear in the `clean` module itself.
2 parents a3b28cb + 3b5d6b4 commit 3cd6c1e

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/librustdoc/clean.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ impl Item {
152152
return None;
153153
}
154154

155+
pub fn is_hidden_from_doc(&self) -> bool {
156+
match self.doc_list() {
157+
Some(ref l) => {
158+
for innerattr in l.iter() {
159+
match *innerattr {
160+
Word(ref s) if "hidden" == *s => return true,
161+
_ => (),
162+
}
163+
}
164+
},
165+
None => ()
166+
}
167+
return false;
168+
}
169+
155170
pub fn is_mod(&self) -> bool {
156171
match self.inner { ModuleItem(..) => true, _ => false }
157172
}
@@ -736,7 +751,7 @@ impl Clean<Type> for ast::Ty {
736751

737752
#[deriving(Clone, Encodable, Decodable)]
738753
pub enum StructField {
739-
HiddenStructField,
754+
HiddenStructField, // inserted later by strip passes
740755
TypedStructField(Type),
741756
}
742757

src/librustdoc/passes.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
3333
};
3434
impl<'a> fold::DocFolder for Stripper<'a> {
3535
fn fold_item(&mut self, i: Item) -> Option<Item> {
36-
for attr in i.attrs.iter() {
37-
match attr {
38-
&clean::List(ref x, ref l) if "doc" == *x => {
39-
for innerattr in l.iter() {
40-
match innerattr {
41-
&clean::Word(ref s) if "hidden" == *s => {
42-
debug!("found one in strip_hidden; removing");
43-
self.stripped.insert(i.id);
44-
return None;
45-
},
46-
_ => (),
47-
}
48-
}
49-
},
50-
_ => ()
36+
if i.is_hidden_from_doc() {
37+
debug!("found one in strip_hidden; removing");
38+
self.stripped.insert(i.id);
39+
40+
// use a dedicated hidden item for given item type if any
41+
match i.inner {
42+
clean::StructFieldItem(..) => {
43+
return Some(clean::Item {
44+
inner: clean::StructFieldItem(clean::HiddenStructField),
45+
..i
46+
});
47+
}
48+
_ => {
49+
return None;
50+
}
5151
}
5252
}
53+
5354
self.fold_item_recur(i)
5455
}
5556
}

0 commit comments

Comments
 (0)