Skip to content

Commit 1827241

Browse files
committed
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.
1 parent f02f739 commit 1827241

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
9393
cx.sess().cstore.iter_crate_data(|n, meta| {
9494
externs.push((n, meta.clean()));
9595
});
96+
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
9697

9798
// Figure out the name of this crate
9899
let input = driver::FileInput(cx.src.clone());
@@ -132,24 +133,33 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
132133
_ => unreachable!(),
133134
};
134135
let mut tmp = Vec::new();
135-
for child in m.items.iter() {
136-
match child.inner {
137-
ModuleItem(..) => {},
136+
for child in m.items.mut_iter() {
137+
let inner = match child.inner {
138+
ModuleItem(ref mut m) => m,
138139
_ => continue,
139-
}
140+
};
140141
let prim = match Primitive::find(child.attrs.as_slice()) {
141142
Some(prim) => prim,
142143
None => continue,
143144
};
144145
primitives.push(prim);
145-
tmp.push(Item {
146+
let mut i = Item {
146147
source: Span::empty(),
147148
name: Some(prim.to_url_str().to_string()),
148-
attrs: child.attrs.clone(),
149-
visibility: Some(ast::Public),
149+
attrs: Vec::new(),
150+
visibility: None,
150151
def_id: ast_util::local_def(prim.to_node_id()),
151152
inner: PrimitiveItem(prim),
152-
});
153+
};
154+
// Push one copy to get indexed for the whole crate, and push a
155+
// another copy in the proper location which will actually get
156+
// documented. The first copy will also serve as a redirect to
157+
// the other copy.
158+
tmp.push(i.clone());
159+
i.visibility = Some(ast::Public);
160+
i.attrs = child.attrs.clone();
161+
inner.items.push(i);
162+
153163
}
154164
m.items.extend(tmp.move_iter());
155165
}
@@ -1027,7 +1037,7 @@ pub enum Type {
10271037
// region, raw, other boxes, mutable
10281038
}
10291039

1030-
#[deriving(Clone, Encodable, Decodable, PartialEq, TotalEq, Hash)]
1040+
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)]
10311041
pub enum Primitive {
10321042
Int, I8, I16, I32, I64,
10331043
Uint, U8, U16, U32, U64,

src/librustdoc/html/render.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ impl DocFolder for Cache {
867867
stack.pop();
868868
self.paths.insert(item.def_id, (stack, item_type::Enum));
869869
}
870+
871+
clean::PrimitiveItem(..) if item.visibility.is_some() => {
872+
self.paths.insert(item.def_id, (self.stack.clone(),
873+
shortty(&item)));
874+
}
875+
870876
_ => {}
871877
}
872878

@@ -1082,21 +1088,21 @@ impl Context {
10821088
writer.flush()
10831089
}
10841090

1091+
// Private modules may survive the strip-private pass if they
1092+
// contain impls for public types. These modules can also
1093+
// contain items such as publicly reexported structures.
1094+
//
1095+
// External crates will provide links to these structures, so
1096+
// these modules are recursed into, but not rendered normally (a
1097+
// flag on the context).
1098+
if !self.render_redirect_pages {
1099+
self.render_redirect_pages = ignore_private_item(&item);
1100+
}
1101+
10851102
match item.inner {
10861103
// modules are special because they add a namespace. We also need to
10871104
// recurse into the items of the module as well.
10881105
clean::ModuleItem(..) => {
1089-
// Private modules may survive the strip-private pass if they
1090-
// contain impls for public types. These modules can also
1091-
// contain items such as publicly reexported structures.
1092-
//
1093-
// External crates will provide links to these structures, so
1094-
// these modules are recursed into, but not rendered normally (a
1095-
// flag on the context).
1096-
if !self.render_redirect_pages {
1097-
self.render_redirect_pages = ignore_private_module(&item);
1098-
}
1099-
11001106
let name = item.name.get_ref().to_string();
11011107
let mut item = Some(item);
11021108
self.recurse(name, |this| {
@@ -1330,7 +1336,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
13301336
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
13311337
try!(document(w, item));
13321338
let mut indices = range(0, items.len()).filter(|i| {
1333-
!ignore_private_module(&items[*i])
1339+
!ignore_private_item(&items[*i])
13341340
}).collect::<Vec<uint>>();
13351341

13361342
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering {
@@ -2016,7 +2022,7 @@ impl<'a> fmt::Show for Sidebar<'a> {
20162022
fn build_sidebar(m: &clean::Module) -> HashMap<String, Vec<String>> {
20172023
let mut map = HashMap::new();
20182024
for item in m.items.iter() {
2019-
if ignore_private_module(item) { continue }
2025+
if ignore_private_item(item) { continue }
20202026

20212027
let short = shortty(item).to_static_str();
20222028
let myname = match item.name {
@@ -2066,12 +2072,13 @@ fn item_primitive(w: &mut fmt::Formatter,
20662072
render_methods(w, it)
20672073
}
20682074

2069-
fn ignore_private_module(it: &clean::Item) -> bool {
2075+
fn ignore_private_item(it: &clean::Item) -> bool {
20702076
match it.inner {
20712077
clean::ModuleItem(ref m) => {
20722078
(m.items.len() == 0 && it.doc_value().is_none()) ||
20732079
it.visibility != Some(ast::Public)
20742080
}
2081+
clean::PrimitiveItem(..) => it.visibility != Some(ast::Public),
20752082
_ => false,
20762083
}
20772084
}

0 commit comments

Comments
 (0)