rustdoc: Put primitives in respective modules

The logical location for the documentation of a primitive is in the module that
declared it was a module for that primitive.
This commit is contained in:
Alex Crichton 2014-06-03 17:55:30 -07:00
parent f02f739a82
commit 1827241840
2 changed files with 40 additions and 23 deletions

View File

@ -93,6 +93,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
cx.sess().cstore.iter_crate_data(|n, meta| {
externs.push((n, meta.clean()));
});
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
// Figure out the name of this crate
let input = driver::FileInput(cx.src.clone());
@ -132,24 +133,33 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
_ => unreachable!(),
};
let mut tmp = Vec::new();
for child in m.items.iter() {
match child.inner {
ModuleItem(..) => {},
for child in m.items.mut_iter() {
let inner = match child.inner {
ModuleItem(ref mut m) => m,
_ => continue,
}
};
let prim = match Primitive::find(child.attrs.as_slice()) {
Some(prim) => prim,
None => continue,
};
primitives.push(prim);
tmp.push(Item {
let mut i = Item {
source: Span::empty(),
name: Some(prim.to_url_str().to_string()),
attrs: child.attrs.clone(),
visibility: Some(ast::Public),
attrs: Vec::new(),
visibility: None,
def_id: ast_util::local_def(prim.to_node_id()),
inner: PrimitiveItem(prim),
});
};
// Push one copy to get indexed for the whole crate, and push a
// another copy in the proper location which will actually get
// documented. The first copy will also serve as a redirect to
// the other copy.
tmp.push(i.clone());
i.visibility = Some(ast::Public);
i.attrs = child.attrs.clone();
inner.items.push(i);
}
m.items.extend(tmp.move_iter());
}
@ -1027,7 +1037,7 @@ pub enum Type {
// region, raw, other boxes, mutable
}
#[deriving(Clone, Encodable, Decodable, PartialEq, TotalEq, Hash)]
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)]
pub enum Primitive {
Int, I8, I16, I32, I64,
Uint, U8, U16, U32, U64,

View File

@ -867,6 +867,12 @@ impl DocFolder for Cache {
stack.pop();
self.paths.insert(item.def_id, (stack, item_type::Enum));
}
clean::PrimitiveItem(..) if item.visibility.is_some() => {
self.paths.insert(item.def_id, (self.stack.clone(),
shortty(&item)));
}
_ => {}
}
@ -1082,21 +1088,21 @@ impl Context {
writer.flush()
}
// Private modules may survive the strip-private pass if they
// contain impls for public types. These modules can also
// contain items such as publicly reexported structures.
//
// External crates will provide links to these structures, so
// these modules are recursed into, but not rendered normally (a
// flag on the context).
if !self.render_redirect_pages {
self.render_redirect_pages = ignore_private_item(&item);
}
match item.inner {
// modules are special because they add a namespace. We also need to
// recurse into the items of the module as well.
clean::ModuleItem(..) => {
// Private modules may survive the strip-private pass if they
// contain impls for public types. These modules can also
// contain items such as publicly reexported structures.
//
// External crates will provide links to these structures, so
// these modules are recursed into, but not rendered normally (a
// flag on the context).
if !self.render_redirect_pages {
self.render_redirect_pages = ignore_private_module(&item);
}
let name = item.name.get_ref().to_string();
let mut item = Some(item);
self.recurse(name, |this| {
@ -1330,7 +1336,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
try!(document(w, item));
let mut indices = range(0, items.len()).filter(|i| {
!ignore_private_module(&items[*i])
!ignore_private_item(&items[*i])
}).collect::<Vec<uint>>();
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering {
@ -2016,7 +2022,7 @@ impl<'a> fmt::Show for Sidebar<'a> {
fn build_sidebar(m: &clean::Module) -> HashMap<String, Vec<String>> {
let mut map = HashMap::new();
for item in m.items.iter() {
if ignore_private_module(item) { continue }
if ignore_private_item(item) { continue }
let short = shortty(item).to_static_str();
let myname = match item.name {
@ -2066,12 +2072,13 @@ fn item_primitive(w: &mut fmt::Formatter,
render_methods(w, it)
}
fn ignore_private_module(it: &clean::Item) -> bool {
fn ignore_private_item(it: &clean::Item) -> bool {
match it.inner {
clean::ModuleItem(ref m) => {
(m.items.len() == 0 && it.doc_value().is_none()) ||
it.visibility != Some(ast::Public)
}
clean::PrimitiveItem(..) => it.visibility != Some(ast::Public),
_ => false,
}
}