Skip to content

Make Rustdoc strip private fields #9843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ pub struct Struct {
struct_type: doctree::StructType,
generics: Generics,
fields: ~[Item],
fields_stripped: bool,
}

impl Clean<Item> for doctree::Struct {
Expand All @@ -699,6 +700,7 @@ impl Clean<Item> for doctree::Struct {
struct_type: self.struct_type,
generics: self.generics.clean(),
fields: self.fields.clean(),
fields_stripped: false,
}),
}
}
Expand All @@ -711,13 +713,15 @@ impl Clean<Item> for doctree::Struct {
pub struct VariantStruct {
struct_type: doctree::StructType,
fields: ~[Item],
fields_stripped: bool,
}

impl Clean<VariantStruct> for syntax::ast::struct_def {
fn clean(&self) -> VariantStruct {
VariantStruct {
struct_type: doctree::struct_type_from_def(self),
fields: self.fields.clean(),
fields_stripped: false,
}
}
}
Expand All @@ -726,6 +730,7 @@ impl Clean<VariantStruct> for syntax::ast::struct_def {
pub struct Enum {
variants: ~[Item],
generics: Generics,
variants_stripped: bool,
}

impl Clean<Item> for doctree::Enum {
Expand All @@ -739,6 +744,7 @@ impl Clean<Item> for doctree::Enum {
inner: EnumItem(Enum {
variants: self.variants.clean(),
generics: self.generics.clean(),
variants_stripped: false,
}),
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub trait DocFolder {
StructItem(i) => {
let mut i = i;
let mut foo = ~[]; swap(&mut foo, &mut i.fields);
let num_fields = foo.len();
i.fields.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
i.fields_stripped |= num_fields != i.fields.len();
StructItem(i)
},
ModuleItem(i) => {
Expand All @@ -36,7 +38,9 @@ pub trait DocFolder {
EnumItem(i) => {
let mut i = i;
let mut foo = ~[]; swap(&mut foo, &mut i.variants);
let num_variants = foo.len();
i.variants.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
i.variants_stripped |= num_variants != i.variants.len();
EnumItem(i)
},
TraitItem(i) => {
Expand Down Expand Up @@ -73,7 +77,9 @@ pub trait DocFolder {
StructVariant(j) => {
let mut j = j;
let mut foo = ~[]; swap(&mut foo, &mut j.fields);
let num_fields = foo.len();
j.fields.extend(&mut foo.move_iter().filter_map(c));
j.fields_stripped |= num_fields != j.fields.len();
VariantItem(Variant {kind: StructVariant(j), ..i2})
},
_ => VariantItem(i2)
Expand Down
14 changes: 12 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,8 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {

fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
write!(w, "<pre class='struct'>");
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields, "", true);
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
s.fields_stripped, "", true);
write!(w, "</pre>");

document(w, it);
Expand Down Expand Up @@ -1312,14 +1313,18 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
}
clean::StructVariant(ref s) => {
render_struct(w, v, None, s.struct_type, s.fields,
" ", false);
s.fields_stripped, " ", false);
}
}
}
_ => unreachable!()
}
write!(w, ",\n");
}

if e.variants_stripped {
write!(w, " // some variants omitted\n");
}
write!(w, "\\}");
}
write!(w, "</pre>");
Expand All @@ -1343,6 +1348,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
g: Option<&clean::Generics>,
ty: doctree::StructType,
fields: &[clean::Item],
fields_stripped: bool,
tab: &str,
structhead: bool) {
write!(w, "{}{}{}",
Expand All @@ -1368,6 +1374,10 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
_ => unreachable!()
}
}

if fields_stripped {
write!(w, " // some fields omitted\n{}", tab);
}
write!(w, "\\}");
}
doctree::Tuple | doctree::Newtype => {
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,13 @@ pub fn strip_private(mut crate: clean::Crate) -> plugins::PluginResult {
}
}

// These are public-by-default (if the enum was public)
clean::VariantItem(*) => {
// These are public-by-default (if the enum/struct was public)
clean::VariantItem(*) | clean::StructFieldItem(*) => {
if i.visibility == Some(ast::private) {
return None;
}
}

// We show these regardless of whether they're public/private
// because it's useful to see sometimes
clean::StructFieldItem(*) => {}

// handled below
clean::ModuleItem(*) => {}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod passes;
pub mod plugins;
pub mod visit_ast;

pub static SCHEMA_VERSION: &'static str = "0.8.0";
pub static SCHEMA_VERSION: &'static str = "0.8.1";

type Pass = (&'static str, // name
extern fn(clean::Crate) -> plugins::PluginResult, // fn
Expand Down