Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rustdoc: Move enum docs into the item tag

  • Loading branch information...
commit d56a4dd04bf6fc3017f32cd4a6b4375c52e66a9c 1 parent 40cbc89
@brson brson authored
View
4 src/rustdoc/attr_pass.rs
@@ -294,7 +294,7 @@ fn fold_enum_should_extract_docs() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let fold = fold::default_seq_fold(srv);
- let doc = fold_enum(fold, doc.topmod.enums[0]);
+ let doc = fold_enum(fold, doc.topmod.enums()[0]);
assert doc.brief == some("a");
assert doc.desc == some("b");
}
@@ -305,7 +305,7 @@ fn fold_enum_should_extract_variant_docs() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let fold = fold::default_seq_fold(srv);
- let doc = fold_enum(fold, doc.topmod.enums[0]);
+ let doc = fold_enum(fold, doc.topmod.enums()[0]);
assert doc.variants[0].desc == some("c");
}
View
6 src/rustdoc/desc_pass.rs
@@ -106,7 +106,7 @@ fn should_execute_op_on_enum_brief() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].brief == some("a");
+ assert doc.topmod.enums()[0].brief == some("a");
}
#[test]
@@ -116,7 +116,7 @@ fn should_execute_op_on_enum_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].desc == some("a");
+ assert doc.topmod.enums()[0].desc == some("a");
}
#[test]
@@ -126,7 +126,7 @@ fn should_execute_op_on_variant_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].variants[0].desc == some("a");
+ assert doc.topmod.enums()[0].variants[0].desc == some("a");
}
#[test]
View
4 src/rustdoc/desc_to_brief_pass.rs
@@ -123,8 +123,8 @@ fn should_promote_enum_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert doc.topmod.enums[0].brief == some("desc");
- assert doc.topmod.enums[0].desc == none;
+ assert doc.topmod.enums()[0].brief == some("desc");
+ assert doc.topmod.enums()[0].desc == none;
}
#[test]
View
14 src/rustdoc/doc.rs
@@ -23,8 +23,7 @@ type moddoc = ~{
items: [itemtag],
mods: modlist,
fns: fnlist,
- consts: constlist,
- enums: enumlist
+ consts: constlist
};
type constdoc = ~{
@@ -84,9 +83,18 @@ type resdoc = ~{
enum modlist = [moddoc];
enum constlist = [constdoc];
enum fnlist = [fndoc];
-enum enumlist = [enumdoc];
impl util for moddoc {
+
+ fn enums() -> [enumdoc] {
+ vec::filter_map(self.items) {|itemtag|
+ alt itemtag {
+ enumtag(enumdoc) { some(enumdoc) }
+ _ { none }
+ }
+ }
+ }
+
fn resources() -> [resdoc] {
vec::filter_map(self.items) {|itemtag|
alt itemtag {
View
22 src/rustdoc/extract.rs
@@ -45,6 +45,11 @@ fn moddoc_from_mod(
desc: none,
items: vec::filter_map(module.items) {|item|
alt item.node {
+ ast::item_enum(variants, _) {
+ some(doc::enumtag(
+ enumdoc_from_enum(item.ident, item.id, variants)
+ ))
+ }
ast::item_res(decl, _, _, _, _) {
some(doc::restag(
resdoc_from_resource(decl, item.ident, item.id)
@@ -88,17 +93,6 @@ fn moddoc_from_mod(
none
}
}
- }),
- enums: doc::enumlist(
- vec::filter_map(module.items) {|item|
- alt item.node {
- ast::item_enum(variants, _) {
- some(enumdoc_from_enum(item.ident, item.id, variants))
- }
- _ {
- none
- }
- }
})
}
}
@@ -200,8 +194,8 @@ fn should_extract_enums() {
let source = "enum e { v }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
- assert doc.topmod.enums[0].id != 0;
- assert doc.topmod.enums[0].name == "e";
+ assert doc.topmod.enums()[0].id != 0;
+ assert doc.topmod.enums()[0].name == "e";
}
#[test]
@@ -209,7 +203,7 @@ fn should_extract_enum_variants() {
let source = "enum e { v }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
- assert doc.topmod.enums[0].variants[0].name == "v";
+ assert doc.topmod.enums()[0].variants[0].name == "v";
}
fn resdoc_from_resource(
View
29 src/rustdoc/fold.rs
@@ -24,8 +24,6 @@ type fold_modlist<T> = fn~(fold: fold<T>, list: doc::modlist) -> doc::modlist;
type fold_fnlist<T> = fn~(fold: fold<T>, list: doc::fnlist) -> doc::fnlist;
type fold_constlist<T> = fn~(
fold: fold<T>, list: doc::constlist) -> doc::constlist;
-type fold_enumlist<T> = fn~(
- fold: fold<T>, list: doc::enumlist) -> doc::enumlist;
type t<T> = {
ctxt: T,
@@ -37,8 +35,7 @@ type t<T> = {
fold_res: fold_res<T>,
fold_modlist: fold_modlist<T>,
fold_fnlist: fold_fnlist<T>,
- fold_constlist: fold_constlist<T>,
- fold_enumlist: fold_enumlist<T>,
+ fold_constlist: fold_constlist<T>
};
@@ -54,8 +51,7 @@ fn mk_fold<T:copy>(
fold_res: fold_res<T>,
fold_modlist: fold_modlist<T>,
fold_fnlist: fold_fnlist<T>,
- fold_constlist: fold_constlist<T>,
- fold_enumlist: fold_enumlist<T>
+ fold_constlist: fold_constlist<T>
) -> fold<T> {
fold({
ctxt: ctxt,
@@ -67,8 +63,7 @@ fn mk_fold<T:copy>(
fold_res: fold_res,
fold_modlist: fold_modlist,
fold_fnlist: fold_fnlist,
- fold_constlist: fold_constlist,
- fold_enumlist: fold_enumlist
+ fold_constlist: fold_constlist
})
}
@@ -83,8 +78,7 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
{|f, d| default_seq_fold_res(f, d)},
{|f, d| default_seq_fold_modlist(f, d)},
{|f, d| default_seq_fold_fnlist(f, d)},
- {|f, d| default_seq_fold_constlist(f, d)},
- {|f, d| default_seq_fold_enumlist(f, d)}
+ {|f, d| default_seq_fold_constlist(f, d)}
)
}
@@ -104,6 +98,9 @@ fn default_seq_fold_mod<T>(
~{
items: vec::map(doc.items) {|itemtag|
alt itemtag {
+ doc::enumtag(enumdoc) {
+ doc::enumtag(fold.fold_enum(fold, enumdoc))
+ }
doc::restag(resdoc) {
doc::restag(fold.fold_res(fold, resdoc))
}
@@ -111,8 +108,7 @@ fn default_seq_fold_mod<T>(
},
mods: fold.fold_modlist(fold, doc.mods),
fns: fold.fold_fnlist(fold, doc.fns),
- consts: fold.fold_constlist(fold, doc.consts),
- enums: fold.fold_enumlist(fold, doc.enums)
+ consts: fold.fold_constlist(fold, doc.consts)
with *doc
}
}
@@ -172,15 +168,6 @@ fn default_seq_fold_constlist<T>(
})
}
-fn default_seq_fold_enumlist<T>(
- fold: fold<T>,
- list: doc::enumlist
-) -> doc::enumlist {
- doc::enumlist(vec::map(*list) {|doc|
- fold.fold_enum(fold, doc)
- })
-}
-
#[test]
fn default_fold_should_produce_same_doc() {
let source = "mod a { fn b() { } mod c { fn d() { } } }";
View
5 src/rustdoc/markdown_pass.rs
@@ -85,10 +85,6 @@ fn write_mod_contents(
write_const(ctxt, constdoc);
}
- for enumdoc in *doc.enums {
- write_enum(ctxt, enumdoc);
- }
-
for fndoc in *doc.fns {
write_fn(ctxt, fndoc);
}
@@ -99,6 +95,7 @@ fn write_mod_contents(
for itemtag in doc.items {
alt itemtag {
+ doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) }
doc::restag(resdoc) { write_res(ctxt, resdoc) }
}
}
View
31 src/rustdoc/prune_undoc_pass.rs
@@ -25,8 +25,7 @@ fn run(
fold_res: fold_res,
fold_modlist: fold_modlist,
fold_fnlist: fold_fnlist,
- fold_constlist: fold_constlist,
- fold_enumlist: fold_enumlist
+ fold_constlist: fold_constlist
with *fold::default_seq_fold(ctxt)
});
fold.fold_crate(fold, doc)
@@ -39,6 +38,14 @@ fn fold_mod(
let doc = ~{
items: vec::filter_map(doc.items) {|itemtag|
alt itemtag {
+ doc::enumtag(enumdoc) {
+ let doc = fold.fold_enum(fold, enumdoc);
+ if fold.ctxt.have_docs {
+ some(doc::enumtag(doc))
+ } else {
+ none
+ }
+ }
doc::restag(resdoc) {
let doc = fold.fold_res(fold, resdoc);
if fold.ctxt.have_docs {
@@ -253,20 +260,6 @@ fn fold_enum(fold: fold::fold<ctxt>, doc: doc::enumdoc) -> doc::enumdoc {
ret doc;
}
-fn fold_enumlist(
- fold: fold::fold<ctxt>,
- list: doc::enumlist
-) -> doc::enumlist {
- doc::enumlist(vec::filter_map(*list) {|doc|
- let doc = fold.fold_enum(fold, doc);
- if fold.ctxt.have_docs {
- some(doc)
- } else {
- none
- }
- })
-}
-
#[test]
fn should_elide_undocumented_enums() {
let source = "enum a { b }";
@@ -274,7 +267,7 @@ fn should_elide_undocumented_enums() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_empty(*doc.topmod.enums);
+ assert vec::is_empty(doc.topmod.enums());
}
#[test]
@@ -284,7 +277,7 @@ fn should_elide_undocumented_variants() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_empty(doc.topmod.enums[0].variants);
+ assert vec::is_empty(doc.topmod.enums()[0].variants);
}
#[test]
@@ -294,7 +287,7 @@ fn should_not_elide_enums_with_documented_variants() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_not_empty(*doc.topmod.enums);
+ assert vec::is_not_empty(doc.topmod.enums());
}
fn fold_res(fold: fold::fold<ctxt>, doc: doc::resdoc) -> doc::resdoc {
View
96 src/rustdoc/prune_unexported_pass.rs
@@ -21,14 +21,22 @@ fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc {
fn fold_mod(fold: fold::fold<astsrv::srv>, doc: doc::moddoc) -> doc::moddoc {
let doc = fold::default_seq_fold_mod(fold, doc);
~{
+ items: exported_items(fold.ctxt, doc),
mods: doc::modlist(exported_mods(fold.ctxt, doc)),
fns: doc::fnlist(exported_fns(fold.ctxt, doc)),
- consts: doc::constlist(exported_consts(fold.ctxt, doc)),
- enums: doc::enumlist(exported_enums(fold.ctxt, doc))
+ consts: doc::constlist(exported_consts(fold.ctxt, doc))
with *doc
}
}
+fn exported_items(srv: astsrv::srv, doc: doc::moddoc) -> [doc::itemtag] {
+ exported_things(
+ srv, doc,
+ exported_items_from_crate,
+ exported_items_from_mod
+ )
+}
+
fn exported_mods(srv: astsrv::srv, doc: doc::moddoc) -> [doc::moddoc] {
exported_things(
srv, doc,
@@ -53,14 +61,6 @@ fn exported_consts(srv: astsrv::srv, doc: doc::moddoc) -> [doc::constdoc] {
)
}
-fn exported_enums(srv: astsrv::srv, doc: doc::moddoc) -> [doc::enumdoc] {
- exported_things(
- srv, doc,
- exported_enums_from_crate,
- exported_enums_from_mod
- )
-}
-
fn exported_things<T>(
srv: astsrv::srv,
doc: doc::moddoc,
@@ -74,6 +74,20 @@ fn exported_things<T>(
}
}
+fn exported_items_from_crate(
+ srv: astsrv::srv,
+ doc: doc::moddoc
+) -> [doc::itemtag] {
+ exported_items_from(srv, doc, is_exported_from_crate)
+}
+
+fn exported_items_from_mod(
+ srv: astsrv::srv,
+ doc: doc::moddoc
+) -> [doc::itemtag] {
+ exported_items_from(srv, doc, bind is_exported_from_mod(_, doc.id, _))
+}
+
fn exported_mods_from_crate(
srv: astsrv::srv,
doc: doc::moddoc
@@ -116,18 +130,32 @@ fn exported_consts_from_mod(
exported_consts_from(srv, doc, bind is_exported_from_mod(_, doc.id, _))
}
-fn exported_enums_from_crate(
- srv: astsrv::srv,
- doc: doc::moddoc
-) -> [doc::enumdoc] {
- exported_enums_from(srv, doc, is_exported_from_crate)
-}
-
-fn exported_enums_from_mod(
+fn exported_items_from(
srv: astsrv::srv,
- doc: doc::moddoc
-) -> [doc::enumdoc] {
- exported_enums_from(srv, doc, bind is_exported_from_mod(_, doc.id, _))
+ doc: doc::moddoc,
+ is_exported: fn(astsrv::srv, str) -> bool
+) -> [doc::itemtag] {
+ vec::filter_map(doc.items) { |itemtag|
+ let name = alt itemtag {
+ doc::enumtag(~{name, _}) { name }
+ doc::restag(~{name, _}) { "FIXME" }
+ };
+ let itemtag = alt itemtag {
+ doc::enumtag(enumdoc) {
+ // Also need to check variant exportedness
+ doc::enumtag(~{
+ variants: exported_variants_from(srv, enumdoc, is_exported)
+ with *enumdoc
+ })
+ }
+ _ { itemtag }
+ };
+ if is_exported(srv, name) {
+ some(itemtag)
+ } else {
+ none
+ }
+ }
}
fn exported_fns_from(
@@ -172,24 +200,6 @@ fn exported_consts_from(
}
}
-fn exported_enums_from(
- srv: astsrv::srv,
- doc: doc::moddoc,
- is_exported: fn(astsrv::srv, str) -> bool
-) -> [doc::enumdoc] {
- vec::filter_map(*doc.enums) { |doc|
- if is_exported(srv, doc.name) {
- some(~{
- variants: exported_variants_from(
- srv, doc, is_exported)
- with *doc
- })
- } else {
- none
- }
- }
-}
-
fn exported_variants_from(
srv: astsrv::srv,
doc: doc::enumdoc,
@@ -293,7 +303,7 @@ fn should_prune_unexported_enums_from_top_mod() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
- assert vec::len(*doc.topmod.enums) == 0u;
+ assert vec::len(doc.topmod.enums()) == 0u;
}
#[test]
@@ -302,7 +312,7 @@ fn should_prune_unexported_enums() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
- assert vec::len(*doc.topmod.mods[0].enums) == 0u;
+ assert vec::len(doc.topmod.mods[0].enums()) == 0u;
}
#[test]
@@ -311,7 +321,7 @@ fn should_prune_unexported_variants_from_top_mod() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
- assert vec::len(doc.topmod.enums[0].variants) == 0u;
+ assert vec::len(doc.topmod.enums()[0].variants) == 0u;
}
#[test]
@@ -320,5 +330,5 @@ fn should_prune_unexported_variants() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
- assert vec::len(doc.topmod.mods[0].enums[0].variants) == 0u;
+ assert vec::len(doc.topmod.mods[0].enums()[0].variants) == 0u;
}
View
6 src/rustdoc/rustdoc.rs
@@ -54,8 +54,7 @@ fn test_run_passes() {
items: [],
mods: doc::modlist([]),
fns: doc::fnlist([]),
- consts: doc::constlist([]),
- enums: doc::enumlist([])
+ consts: doc::constlist([])
}
}
}
@@ -73,8 +72,7 @@ fn test_run_passes() {
items: [],
mods: doc::modlist([]),
fns: doc::fnlist([]),
- consts: doc::constlist([]),
- enums: doc::enumlist([])
+ consts: doc::constlist([])
}
}
}
View
2  src/rustdoc/tystr_pass.rs
@@ -224,7 +224,7 @@ fn should_add_variant_sigs() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
- assert doc.topmod.enums[0].variants[0].sig == some("b(int)");
+ assert doc.topmod.enums()[0].variants[0].sig == some("b(int)");
}
fn fold_res(
Please sign in to comment.
Something went wrong with that request. Please try again.