Skip to content

Commit 534d10f

Browse files
committed
---
yaml --- r: 13945 b: refs/heads/try c: 496205c h: refs/heads/master i: 13943: 1a75dbd v: v3
1 parent 5ca127b commit 534d10f

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 23042a3566a0004fdb34adee183fd4ae32f590c7
5+
refs/heads/try: 496205c85f9e0450535514472cd6fc47d5462415
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustdoc/attr_parser.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import core::tuple;
1111

1212
export crate_attrs, mod_attrs, fn_attrs, arg_attrs,
1313
const_attrs, enum_attrs, variant_attrs, res_attrs,
14-
iface_attrs, method_attrs;
14+
iface_attrs, method_attrs, impl_attrs;
1515
export parse_crate, parse_mod, parse_fn, parse_const,
1616
parse_enum, parse_variant, parse_res,
17-
parse_iface, parse_method;
17+
parse_iface, parse_method, parse_impl;
1818

1919
type crate_attrs = {
2020
name: option<str>
@@ -63,6 +63,11 @@ type iface_attrs = {
6363
desc: option<str>
6464
};
6565

66+
type impl_attrs = {
67+
brief: option<str>,
68+
desc: option<str>
69+
};
70+
6671
type method_attrs = fn_attrs;
6772

6873
#[cfg(test)]
@@ -499,3 +504,7 @@ fn parse_iface(attrs: [ast::attribute]) -> iface_attrs {
499504
fn parse_method(attrs: [ast::attribute]) -> method_attrs {
500505
parse_fn(attrs)
501506
}
507+
508+
fn parse_impl(attrs: [ast::attribute]) -> impl_attrs {
509+
parse_basic(attrs)
510+
}

branches/try/src/rustdoc/attr_pass.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn run(
2626
fold_const: fold_const,
2727
fold_enum: fold_enum,
2828
fold_res: fold_res,
29-
fold_iface: fold_iface
29+
fold_iface: fold_iface,
30+
fold_impl: fold_impl
3031
with *fold::default_seq_fold(srv)
3132
});
3233
fold.fold_crate(fold, doc)
@@ -398,9 +399,14 @@ fn merge_method_attrs(
398399
(method.ident, attr_parser::parse_method(method.attrs))
399400
}
400401
}
401-
_ {
402-
fail "Undocumented invariant in merge_method_attrs";
402+
ast_map::node_item(@{
403+
node: ast::item_impl(_, _, _, methods), _
404+
}) {
405+
vec::map(methods) {|method|
406+
(method.ident, attr_parser::parse_method(method.attrs))
407+
}
403408
}
409+
_ { fail "unexpected item" }
404410
}
405411
};
406412

@@ -448,3 +454,50 @@ fn should_extract_iface_method_docs() {
448454
assert doc.topmod.ifaces()[0].methods[0].return.desc == some("return");
449455
assert doc.topmod.ifaces()[0].methods[0].failure == some("failure");
450456
}
457+
458+
459+
fn fold_impl(
460+
fold: fold::fold<astsrv::srv>,
461+
doc: doc::impldoc
462+
) -> doc::impldoc {
463+
let srv = fold.ctxt;
464+
let doc = fold::default_seq_fold_impl(fold, doc);
465+
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_impl);
466+
467+
{
468+
brief: attrs.brief,
469+
desc: attrs.desc,
470+
methods: merge_method_attrs(srv, doc.id, doc.methods)
471+
with doc
472+
}
473+
}
474+
475+
#[test]
476+
fn should_extract_impl_docs() {
477+
let source = "#[doc = \"whatever\"] impl i for int { fn a() { } }";
478+
let srv = astsrv::mk_srv_from_str(source);
479+
let doc = extract::from_srv(srv, "");
480+
let doc = run(srv, doc);
481+
assert doc.topmod.impls()[0].desc == some("whatever");
482+
}
483+
484+
#[test]
485+
fn should_extract_impl_method_docs() {
486+
let source = "impl i for int {\
487+
#[doc(\
488+
brief = \"brief\",\
489+
desc = \"desc\",\
490+
args(a = \"a\"),\
491+
return = \"return\",\
492+
failure = \"failure\")]\
493+
fn f(a: bool) -> bool { }\
494+
}";
495+
let srv = astsrv::mk_srv_from_str(source);
496+
let doc = extract::from_srv(srv, "");
497+
let doc = run(srv, doc);
498+
assert doc.topmod.impls()[0].methods[0].brief == some("brief");
499+
assert doc.topmod.impls()[0].methods[0].desc == some("desc");
500+
assert doc.topmod.impls()[0].methods[0].args[0].desc == some("a");
501+
assert doc.topmod.impls()[0].methods[0].return.desc == some("return");
502+
assert doc.topmod.impls()[0].methods[0].failure == some("failure");
503+
}

0 commit comments

Comments
 (0)