Skip to content

Commit f9f9388

Browse files
committed
rustdoc: Apply string ops to impl docs
1 parent 3f1534a commit f9f9388

File tree

1 file changed

+81
-18
lines changed

1 file changed

+81
-18
lines changed

src/rustdoc/desc_pass.rs

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ fn run(
2121
fold_fn: fold_fn,
2222
fold_enum: fold_enum,
2323
fold_res: fold_res,
24-
fold_iface: fold_iface
24+
fold_iface: fold_iface,
25+
fold_impl: fold_impl
2526
with *fold::default_seq_fold(op)
2627
});
2728
fold.fold_crate(fold, doc)
@@ -104,24 +105,37 @@ fn fold_iface(fold: fold::fold<op>, doc: doc::ifacedoc) -> doc::ifacedoc {
104105
{
105106
brief: maybe_apply_op(fold.ctxt, doc.brief),
106107
desc: maybe_apply_op(fold.ctxt, doc.desc),
107-
methods: vec::map(doc.methods) {|doc|
108-
{
109-
brief: maybe_apply_op(fold.ctxt, doc.brief),
110-
desc: maybe_apply_op(fold.ctxt, doc.desc),
111-
args: vec::map(doc.args) {|doc|
112-
{
113-
desc: maybe_apply_op(fold.ctxt, doc.desc)
114-
with doc
115-
}
116-
},
117-
return: {
118-
desc: maybe_apply_op(fold.ctxt, doc.return.desc)
119-
with doc.return
120-
},
121-
failure: maybe_apply_op(fold.ctxt, doc.failure)
122-
with doc
123-
}
108+
methods: apply_to_methods(fold.ctxt, doc.methods)
109+
with doc
110+
}
111+
}
112+
113+
fn apply_to_methods(op: op, docs: [doc::methoddoc]) -> [doc::methoddoc] {
114+
vec::map(docs) {|doc|
115+
{
116+
brief: maybe_apply_op(op, doc.brief),
117+
desc: maybe_apply_op(op, doc.desc),
118+
args: vec::map(doc.args) {|doc|
119+
{
120+
desc: maybe_apply_op(op, doc.desc)
121+
with doc
122+
}
123+
},
124+
return: {
125+
desc: maybe_apply_op(op, doc.return.desc)
126+
with doc.return
127+
},
128+
failure: maybe_apply_op(op, doc.failure)
129+
with doc
124130
}
131+
}
132+
}
133+
134+
fn fold_impl(fold: fold::fold<op>, doc: doc::impldoc) -> doc::impldoc {
135+
{
136+
brief: maybe_apply_op(fold.ctxt, doc.brief),
137+
desc: maybe_apply_op(fold.ctxt, doc.desc),
138+
methods: apply_to_methods(fold.ctxt, doc.methods)
125139
with doc
126140
}
127141
}
@@ -211,6 +225,55 @@ fn should_execute_op_on_iface_method_failure_condition() {
211225
assert doc.topmod.ifaces()[0].methods[0].failure == some("a");
212226
}
213227

228+
#[test]
229+
fn should_execute_op_on_impl_brief() {
230+
let doc = test::mk_doc(
231+
"#[doc(brief = \" a \")] impl i for int { fn a() { } }");
232+
assert doc.topmod.impls()[0].brief == some("a");
233+
}
234+
235+
#[test]
236+
fn should_execute_op_on_impl_desc() {
237+
let doc = test::mk_doc(
238+
"#[doc(desc = \" a \")] impl i for int { fn a() { } }");
239+
assert doc.topmod.impls()[0].desc == some("a");
240+
}
241+
242+
#[test]
243+
fn should_execute_op_on_impl_method_brief() {
244+
let doc = test::mk_doc(
245+
"impl i for int { #[doc(brief = \" a \")] fn a() { } }");
246+
assert doc.topmod.impls()[0].methods[0].brief == some("a");
247+
}
248+
249+
#[test]
250+
fn should_execute_op_on_impl_method_desc() {
251+
let doc = test::mk_doc(
252+
"impl i for int { #[doc(desc = \" a \")] fn a() { } }");
253+
assert doc.topmod.impls()[0].methods[0].desc == some("a");
254+
}
255+
256+
#[test]
257+
fn should_execute_op_on_impl_method_args() {
258+
let doc = test::mk_doc(
259+
"impl i for int { #[doc(args(a = \" a \"))] fn a(a: bool) { } }");
260+
assert doc.topmod.impls()[0].methods[0].args[0].desc == some("a");
261+
}
262+
263+
#[test]
264+
fn should_execute_op_on_impl_method_return() {
265+
let doc = test::mk_doc(
266+
"impl i for int { #[doc(return = \" a \")] fn a() -> int { fail } }");
267+
assert doc.topmod.impls()[0].methods[0].return.desc == some("a");
268+
}
269+
270+
#[test]
271+
fn should_execute_op_on_impl_method_failure_condition() {
272+
let doc = test::mk_doc(
273+
"impl i for int { #[doc(failure = \" a \")] fn a() { } }");
274+
assert doc.topmod.impls()[0].methods[0].failure == some("a");
275+
}
276+
214277
#[cfg(test)]
215278
mod test {
216279
fn mk_doc(source: str) -> doc::cratedoc {

0 commit comments

Comments
 (0)