Skip to content

Commit 96fba8c

Browse files
committed
---
yaml --- r: 21974 b: refs/heads/snap-stage3 c: 60443d4 h: refs/heads/master v: v3
1 parent 491fa02 commit 96fba8c

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c32cde16ab1cd7d8483d176591c22dbac3520833
4+
refs/heads/snap-stage3: 60443d48881bfbc7a305e807390e74b327f100b8
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! Prune things that are private
2+
3+
export mk_pass;
4+
5+
fn mk_pass() -> Pass {
6+
{
7+
name: ~"prune_private",
8+
f: run
9+
}
10+
}
11+
12+
fn run(srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc {
13+
let fold = fold::Fold({
14+
fold_mod: fold_mod,
15+
.. *fold::default_any_fold(srv)
16+
});
17+
fold.fold_doc(fold, doc)
18+
}
19+
20+
fn fold_mod(
21+
fold: fold::Fold<astsrv::Srv>,
22+
doc: doc::ModDoc
23+
) -> doc::ModDoc {
24+
let doc = fold::default_any_fold_mod(fold, doc);
25+
26+
doc::ModDoc_({
27+
items: do doc.items.filter |ItemTag| {
28+
is_visible(fold.ctxt, ItemTag.item())
29+
},
30+
.. *doc
31+
})
32+
}
33+
34+
fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
35+
use syntax::ast_map;
36+
use syntax::ast;
37+
38+
let id = doc.id;
39+
40+
do astsrv::exec(srv) |ctxt| {
41+
match ctxt.ast_map.get(id) {
42+
ast_map::node_item(item, _) => {
43+
item.vis == ast::public
44+
}
45+
_ => util::unreachable()
46+
}
47+
}
48+
}
49+
50+
#[test]
51+
fn should_prune_items_without_pub_modifier() {
52+
let doc = test::mk_doc(~"mod a { }");
53+
assert vec::is_empty(doc.cratemod().mods());
54+
}
55+
56+
#[cfg(test)]
57+
mod test {
58+
fn mk_doc(source: ~str) -> doc::Doc {
59+
do astsrv::from_str(source) |srv| {
60+
let doc = extract::from_srv(srv, ~"");
61+
run(srv, doc)
62+
}
63+
}
64+
}
65+

branches/snap-stage3/src/rustdoc/rustdoc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ mod sort_item_type_pass;
4949
mod page_pass;
5050
mod sectionalize_pass;
5151
mod escape_pass;
52+
mod prune_private_pass;

branches/snap-stage3/src/rustdoc/rustdoc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ fn run(config: Config) {
5353
escape_pass::mk_pass(),
5454
// Remove things marked doc(hidden)
5555
prune_hidden_pass::mk_pass(),
56+
// Remove things that are private
57+
// XXX enable this after 'export' is removed in favor of 'pub'
58+
// prune_private_pass::mk_pass(),
5659
// Extract brief documentation from the full descriptions
5760
desc_to_brief_pass::mk_pass(),
5861
// Massage the text to remove extra indentation

0 commit comments

Comments
 (0)