Skip to content

Commit f9ace7c

Browse files
committed
---
yaml --- r: 11688 b: refs/heads/master c: 7f66df7 h: refs/heads/master v: v3
1 parent c86aceb commit f9ace7c

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 90ac69904f758cc4ae3d86d4b6bf4a1602606b3f
2+
refs/heads/master: 7f66df714a948c76f93aef9fcdd794cd1ed6b26d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/attr_parser.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export crate_attrs, basic_attrs, fn_attrs, arg_attrs,
1313
variant_attrs, res_attrs, method_attrs;
1414
export parse_crate, parse_basic, parse_fn,
1515
parse_variant, parse_res, parse_method;
16+
export parse_hidden;
1617

1718
type crate_attrs = {
1819
name: option<str>
@@ -363,3 +364,28 @@ fn shoulde_parse_resource_arg() {
363364
fn parse_method(attrs: [ast::attribute]) -> method_attrs {
364365
parse_fn(attrs)
365366
}
367+
368+
fn parse_hidden(attrs: [ast::attribute]) -> bool {
369+
parse_short_doc_or(
370+
attrs,
371+
{|_desc| false },
372+
{|metas, _brief, _desc|
373+
let hiddens = attr::find_meta_items_by_name(metas, "hidden");
374+
vec::is_not_empty(hiddens)
375+
}
376+
)
377+
}
378+
379+
#[test]
380+
fn shoulde_parse_hidden_attribute() {
381+
let source = "#[doc(hidden)]";
382+
let attrs = test::parse_attributes(source);
383+
assert parse_hidden(attrs) == true;
384+
}
385+
386+
#[test]
387+
fn shoulde_not_parse_non_hidden_attribute() {
388+
let source = "#[doc = \"\"]";
389+
let attrs = test::parse_attributes(source);
390+
assert parse_hidden(attrs) == false;
391+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#[doc = "Prunes things with the #[doc(hidden)] attribute"];
2+
3+
export mk_pass;
4+
5+
fn mk_pass() -> pass {
6+
{
7+
name: "prune_hidden",
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+
with *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+
{
27+
items: vec::filter(doc.items) {|itemtag|
28+
!is_hidden(fold.ctxt, itemtag.item())
29+
}
30+
with doc
31+
}
32+
}
33+
34+
fn is_hidden(srv: astsrv::srv, doc: doc::itemdoc) -> bool {
35+
import rustc::middle::ast_map;
36+
37+
let id = doc.id;
38+
astsrv::exec(srv) {|ctxt|
39+
let attrs = alt ctxt.ast_map.get(id) {
40+
ast_map::node_item(item, _) { item.attrs }
41+
_ { [] }
42+
};
43+
attr_parser::parse_hidden(attrs)
44+
}
45+
}
46+
47+
#[test]
48+
fn should_prune_hidden_items() {
49+
let doc = test::mk_doc("#[doc(hidden)] mod a { }");
50+
assert vec::is_empty(doc.cratemod().mods())
51+
}
52+
53+
#[cfg(test)]
54+
mod test {
55+
fn mk_doc(source: str) -> doc::doc {
56+
astsrv::from_str(source) {|srv|
57+
let doc = extract::from_srv(srv, "");
58+
run(srv, doc)
59+
}
60+
}
61+
}

trunk/src/rustdoc/rustdoc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod tystr_pass;
2727
mod prune_undoc_details_pass;
2828
mod prune_undoc_items_pass;
2929
mod prune_unexported_pass;
30+
mod prune_hidden_pass;
3031
mod desc_to_brief_pass;
3132
mod desc_pass;
3233
mod unindent_pass;

trunk/src/rustdoc/rustdoc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn run(config: config::config) {
146146
prune_undoc_details_pass::mk_pass(),
147147
// FIXME: This pass should be optional
148148
// prune_undoc_items_pass::mk_pass(),
149+
prune_hidden_pass::mk_pass(),
149150
desc_to_brief_pass::mk_pass(),
150151
trim_pass::mk_pass(),
151152
unindent_pass::mk_pass(),

0 commit comments

Comments
 (0)