rustdoc: Change fndoc's arg list to a vec from map
This commit is contained in:
parent
b6ad840c18
commit
63dcc64275
@ -1,4 +1,3 @@
|
||||
import std::map;
|
||||
import rustc::syntax::ast;
|
||||
|
||||
export parse_fn;
|
||||
@ -8,7 +7,6 @@ fn parse_fn(
|
||||
id: ast::node_id,
|
||||
attrs: [ast::attribute]
|
||||
) -> doc::fndoc {
|
||||
let noargdocs = map::new_str_hash::<str>();
|
||||
let _fndoc = none;
|
||||
for attr: ast::attribute in attrs {
|
||||
alt attr.node.value.node {
|
||||
@ -20,7 +18,7 @@ fn parse_fn(
|
||||
brief: value,
|
||||
desc: none,
|
||||
return: none,
|
||||
args: noargdocs
|
||||
args: []
|
||||
});
|
||||
}
|
||||
ast::meta_list("doc", docs) {
|
||||
@ -39,7 +37,7 @@ fn parse_fn(
|
||||
brief: "_undocumented_",
|
||||
desc: none,
|
||||
return: none,
|
||||
args: noargdocs
|
||||
args: []
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -67,7 +65,7 @@ fn parse_fn_(
|
||||
let brief = none;
|
||||
let desc = none;
|
||||
let return = none;
|
||||
let argdocs = map::new_str_hash::<str>();
|
||||
let argdocs = [];
|
||||
let argdocsfound = none;
|
||||
for item: @ast::meta_item in items {
|
||||
alt item.node {
|
||||
@ -95,10 +93,10 @@ fn parse_fn_(
|
||||
some(ds) {
|
||||
for d: @ast::meta_item in ds {
|
||||
alt d.node {
|
||||
ast::meta_name_value(key, {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
argdocs.insert(key, value);
|
||||
}
|
||||
ast::meta_name_value(key, {node: ast::lit_str(value),
|
||||
span: _}) {
|
||||
argdocs += [(key, value)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,7 +144,7 @@ mod tests {
|
||||
assert doc.brief == "_undocumented_";
|
||||
assert doc.desc == none;
|
||||
assert doc.return == none;
|
||||
assert doc.args.size() == 0u;
|
||||
assert vec::len(doc.args) == 0u;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -186,8 +184,8 @@ mod tests {
|
||||
let source = "#[doc(args(a = \"arg a\", b = \"arg b\"))]";
|
||||
let attrs = parse_attributes(source);
|
||||
let doc = parse_fn("f", 0, attrs);
|
||||
assert doc.args.get("a") == "arg a";
|
||||
assert doc.args.get("b") == "arg b";
|
||||
assert doc.args[0] == ("a", "arg a");
|
||||
assert doc.args[1] == ("b", "arg b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,3 @@
|
||||
import std::map;
|
||||
|
||||
type ast_id = int;
|
||||
|
||||
type cratedoc = ~{
|
||||
@ -18,7 +16,7 @@ type fndoc = ~{
|
||||
brief: str,
|
||||
desc: option::t<str>,
|
||||
return: option::t<str>,
|
||||
args: map::hashmap<str, str>
|
||||
args: [(str, str)]
|
||||
};
|
||||
|
||||
// Just to break the structural recursive types
|
||||
|
@ -98,15 +98,9 @@ fn write_fndoc(ctxt: ctxt, ident: str, doc: doc::fndoc, decl: ast::fn_decl) {
|
||||
}
|
||||
none. { }
|
||||
}
|
||||
for arg: ast::arg in decl.inputs {
|
||||
ctxt.w.write_str("### Argument `" + arg.ident + "`: ");
|
||||
ctxt.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`");
|
||||
alt doc.args.find(arg.ident) {
|
||||
some(_d) {
|
||||
ctxt.w.write_line(_d);
|
||||
}
|
||||
none. { }
|
||||
};
|
||||
for (arg, desc) in doc.args {
|
||||
ctxt.w.write_str("### Argument `" + arg + "`: ");
|
||||
ctxt.w.write_str(desc);
|
||||
}
|
||||
ctxt.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`");
|
||||
alt doc.return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user