File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change @@ -49,3 +49,4 @@ mod sort_item_type_pass;
49
49
mod page_pass;
50
50
mod sectionalize_pass;
51
51
mod escape_pass;
52
+ mod prune_private_pass;
Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ fn run(config: Config) {
53
53
escape_pass:: mk_pass ( ) ,
54
54
// Remove things marked doc(hidden)
55
55
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(),
56
59
// Extract brief documentation from the full descriptions
57
60
desc_to_brief_pass:: mk_pass ( ) ,
58
61
// Massage the text to remove extra indentation
You can’t perform that action at this time.
0 commit comments