diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 9c60b90a1fc..7437d608771 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -14,7 +14,6 @@ pub use self::Type::*; pub use self::PrimitiveType::*; pub use self::TypeKind::*; -pub use self::StructField::*; pub use self::VariantKind::*; pub use self::Mutability::*; pub use self::Import::*; @@ -309,6 +308,15 @@ impl Item { pub fn is_stripped(&self) -> bool { match self.inner { StrippedItem(..) => true, _ => false } } + pub fn has_stripped_fields(&self) -> Option { + match self.inner { + StructItem(ref _struct) => Some(_struct.fields_stripped), + VariantItem(Variant { kind: StructVariant(ref vstruct)} ) => { + Some(vstruct.fields_stripped) + }, + _ => None, + } + } pub fn stability_class(&self) -> String { self.stability.as_ref().map(|ref s| { @@ -346,7 +354,7 @@ pub enum ItemEnum { TyMethodItem(TyMethod), /// A method with a body. MethodItem(Method), - StructFieldItem(StructField), + StructFieldItem(Type), VariantItem(Variant), /// `fn`s from an extern block ForeignFunctionItem(Function), @@ -1740,12 +1748,6 @@ impl<'tcx> Clean for ty::Ty<'tcx> { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum StructField { - HiddenStructField, // inserted later by strip passes - TypedStructField(Type), -} - impl Clean for hir::StructField { fn clean(&self, cx: &DocContext) -> Item { Item { @@ -1756,7 +1758,7 @@ impl Clean for hir::StructField { stability: get_stability(cx, cx.map.local_def_id(self.id)), deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)), def_id: cx.map.local_def_id(self.id), - inner: StructFieldItem(TypedStructField(self.ty.clean(cx))), + inner: StructFieldItem(self.ty.clean(cx)), } } } @@ -1773,7 +1775,7 @@ impl<'tcx> Clean for ty::FieldDefData<'tcx, 'static> { stability: get_stability(cx, self.did), deprecation: get_deprecation(cx, self.did), def_id: self.did, - inner: StructFieldItem(TypedStructField(self.unsubst_ty().clean(cx))), + inner: StructFieldItem(self.unsubst_ty().clean(cx)), } } } @@ -1904,9 +1906,7 @@ impl<'tcx> Clean for ty::VariantDefData<'tcx, 'static> { def_id: field.did, stability: get_stability(cx, field.did), deprecation: get_deprecation(cx, field.did), - inner: StructFieldItem( - TypedStructField(field.unsubst_ty().clean(cx)) - ) + inner: StructFieldItem(field.unsubst_ty().clean(cx)) } }).collect() }) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 782b3cc52e8..678a9d75f96 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1020,13 +1020,9 @@ impl DocFolder for Cache { } _ => ((None, Some(&*self.stack)), false) }; - let hidden_field = match item.inner { - clean::StructFieldItem(clean::HiddenStructField) => true, - _ => false - }; match parent { - (parent, Some(path)) if is_method || (!self.stripped_mod && !hidden_field) => { + (parent, Some(path)) if is_method || (!self.stripped_mod) => { // Needed to determine `self` type. let parent_basename = self.parent_stack.first().and_then(|parent| { match self.paths.get(parent) { @@ -1051,7 +1047,7 @@ impl DocFolder for Cache { }); } } - (Some(parent), None) if is_method || (!self.stripped_mod && !hidden_field)=> { + (Some(parent), None) if is_method || (!self.stripped_mod)=> { if parent.is_local() { // We have a parent, but we don't know where they're // defined yet. Wait for later to index this item. @@ -2165,8 +2161,7 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, document(w, cx, it)?; let mut fields = s.fields.iter().filter(|f| { match f.inner { - clean::StructFieldItem(clean::HiddenStructField) => false, - clean::StructFieldItem(clean::TypedStructField(..)) => true, + clean::StructFieldItem(..) => true, _ => false, } }).peekable(); @@ -2256,7 +2251,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner { let fields = s.fields.iter().filter(|f| { match f.inner { - clean::StructFieldItem(clean::TypedStructField(..)) => true, + clean::StructFieldItem(..) => true, _ => false, } }); @@ -2315,24 +2310,17 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, match ty { doctree::Plain => { write!(w, " {{\n{}", tab)?; - let mut fields_stripped = false; for field in fields { - match field.inner { - clean::StructFieldItem(clean::HiddenStructField) => { - fields_stripped = true; - } - clean::StructFieldItem(clean::TypedStructField(ref ty)) => { - write!(w, " {}{}: {},\n{}", - VisSpace(field.visibility), - field.name.as_ref().unwrap(), - *ty, - tab)?; - } - _ => unreachable!(), - }; + if let clean::StructFieldItem(ref ty) = field.inner { + write!(w, " {}{}: {},\n{}", + VisSpace(field.visibility), + field.name.as_ref().unwrap(), + *ty, + tab)?; + } } - if fields_stripped { + if it.has_stripped_fields().unwrap() { write!(w, " // some fields omitted\n{}", tab)?; } write!(w, "}}")?; @@ -2344,10 +2332,10 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, write!(w, ", ")?; } match field.inner { - clean::StructFieldItem(clean::HiddenStructField) => { + clean::StrippedItem(box clean::StructFieldItem(..)) => { write!(w, "_")? } - clean::StructFieldItem(clean::TypedStructField(ref ty)) => { + clean::StructFieldItem(ref ty) => { write!(w, "{}{}", VisSpace(field.visibility), *ty)? } _ => unreachable!() diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 06d84fc8822..f93ecb46228 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -40,13 +40,9 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { // 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 - }); + clean::StructFieldItem(..) | clean::ModuleItem(..) => { + return Strip(i).fold() } - clean::ModuleItem(..) => return Strip(i).fold(), _ => return None, } } @@ -130,7 +126,8 @@ impl<'a> fold::DocFolder for Stripper<'a> { clean::StructItem(..) | clean::EnumItem(..) | clean::TraitItem(..) | clean::FunctionItem(..) | clean::VariantItem(..) | clean::MethodItem(..) | - clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) => { + clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) | + clean::ConstantItem(..) => { if i.def_id.is_local() { if !self.access_levels.is_exported(i.def_id) { return None; @@ -138,18 +135,9 @@ impl<'a> fold::DocFolder for Stripper<'a> { } } - clean::ConstantItem(..) => { - if i.def_id.is_local() && !self.access_levels.is_exported(i.def_id) { - return None; - } - } - clean::StructFieldItem(..) => { if i.visibility != Some(hir::Public) { - return Some(clean::Item { - inner: clean::StructFieldItem(clean::HiddenStructField), - ..i - }) + return Strip(i).fold(); } } diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs new file mode 100644 index 00000000000..c4327f70728 --- /dev/null +++ b/src/test/rustdoc/structfields.rs @@ -0,0 +1,44 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// @has structfields/struct.Foo.html +pub struct Foo { + // @has - //pre "pub a: ()" + pub a: (), + // @has - //pre "// some fields omitted" + // @!has - //pre "b: ()" + b: (), + // @!has - //pre "c: usize" + #[doc(hidden)] + c: usize, + // @has - //pre "pub d: usize" + pub d: usize, +} + +// @has structfields/struct.Bar.html +pub struct Bar { + // @has - //pre "pub a: ()" + pub a: (), + // @!has - //pre "// some fields omitted" +} + +// @has structfields/enum.Qux.html +pub enum Qux { + Quz { + // @has - //pre "a: ()" + a: (), + // @!has - //pre "b: ()" + #[doc(hidden)] + b: (), + // @has - //pre "c: usize" + c: usize, + // @has - //pre "// some fields omitted" + }, +}