Skip to content

Commit 5ca127b

Browse files
committed
---
yaml --- r: 13944 b: refs/heads/try c: 23042a3 h: refs/heads/master v: v3
1 parent 1a75dbd commit 5ca127b

File tree

2 files changed

+162
-26
lines changed

2 files changed

+162
-26
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: b7108d71a52ae7d89d9d806eb8fcea7e50638bc1
5+
refs/heads/try: 23042a3566a0004fdb34adee183fd4ae32f590c7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustdoc/tystr_pass.rs

Lines changed: 161 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ fn run(
2020
fold_const: fold_const,
2121
fold_enum: fold_enum,
2222
fold_res: fold_res,
23-
fold_iface: fold_iface
23+
fold_iface: fold_iface,
24+
fold_impl: fold_impl
2425
with *fold::default_seq_fold(srv)
2526
});
2627
fold.fold_crate(fold, doc)
@@ -291,30 +292,35 @@ fn fold_iface(
291292
fold: fold::fold<astsrv::srv>,
292293
doc: doc::ifacedoc
293294
) -> doc::ifacedoc {
294-
295-
let srv = fold.ctxt;
296-
297295
{
298-
methods: vec::map(doc.methods) {|methoddoc|
299-
{
300-
args: merge_method_arg_tys(
301-
srv,
302-
doc.id,
303-
methoddoc.args,
304-
methoddoc.name),
305-
return: merge_method_ret_ty(
306-
srv,
307-
doc.id,
308-
methoddoc.return,
309-
methoddoc.name),
310-
sig: get_method_sig(srv, doc.id, methoddoc.name)
311-
with methoddoc
312-
}
313-
}
296+
methods: merge_methods(fold.ctxt, doc.id, doc.methods)
314297
with doc
315298
}
316299
}
317300

301+
fn merge_methods(
302+
srv: astsrv::srv,
303+
item_id: doc::ast_id,
304+
docs: [doc::methoddoc]
305+
) -> [doc::methoddoc] {
306+
vec::map(docs) {|doc|
307+
{
308+
args: merge_method_arg_tys(
309+
srv,
310+
item_id,
311+
doc.args,
312+
doc.name),
313+
return: merge_method_ret_ty(
314+
srv,
315+
item_id,
316+
doc.return,
317+
doc.name),
318+
sig: get_method_sig(srv, item_id, doc.name)
319+
with doc
320+
}
321+
}
322+
}
323+
318324
fn merge_method_ret_ty(
319325
srv: astsrv::srv,
320326
item_id: doc::ast_id,
@@ -351,7 +357,19 @@ fn get_method_ret_ty(
351357
_ { fail "get_method_ret_ty: undocumented invariant"; }
352358
}
353359
}
354-
_ { fail "get_method_ret_ty: undocumented invariant"; }
360+
ast_map::node_item(@{
361+
node: ast::item_impl(_, _, _, methods), _
362+
}) {
363+
alt vec::find(methods) {|method|
364+
method.ident == method_name
365+
} {
366+
some(method) {
367+
ret_ty_to_str(method.decl)
368+
}
369+
_ { fail "get_method_ret_ty: undocumented invariant"; }
370+
}
371+
}
372+
_ { fail }
355373
}
356374
}
357375
}
@@ -372,10 +390,22 @@ fn get_method_sig(
372390
some(method) {
373391
some(pprust::fun_to_str(method.decl, method.ident, []))
374392
}
375-
_ { fail "get_method_ret_sig: undocumented invariant"; }
393+
_ { fail "get_method_sig: undocumented invariant"; }
394+
}
395+
}
396+
ast_map::node_item(@{
397+
node: ast::item_impl(_, _, _, methods), _
398+
}) {
399+
alt vec::find(methods) {|method|
400+
method.ident == method_name
401+
} {
402+
some(method) {
403+
some(pprust::fun_to_str(method.decl, method.ident, []))
404+
}
405+
_ { fail "get_method_sig: undocumented invariant"; }
376406
}
377407
}
378-
_ { fail "get_method_ret_sig: undocumented invariant"; }
408+
_ { fail "get_method_sig: undocumented invariant"; }
379409
}
380410
}
381411
}
@@ -412,10 +442,22 @@ fn get_method_arg_tys(
412442
some(method) {
413443
decl_arg_tys(method.decl)
414444
}
415-
_ { fail "get_method_arg_tys: undocumented invariant"; }
445+
_ { fail "get_method_arg_tys: expected method"; }
446+
}
447+
}
448+
ast_map::node_item(@{
449+
node: ast::item_impl(_, _, _, methods), _
450+
}) {
451+
alt vec::find(methods) {|method|
452+
method.ident == method_name
453+
} {
454+
some(method) {
455+
decl_arg_tys(method.decl)
456+
}
457+
_ { fail "get_method_arg_tys: expected method"; }
416458
}
417459
}
418-
_ { fail "get_method_arg_tys: undocumented invariant"; }
460+
_ { fail }
419461
}
420462
}
421463
}
@@ -457,3 +499,97 @@ fn should_add_iface_method_arg_types() {
457499
assert fn_.args[0].ty == some("int");
458500
assert fn_.args[1].ty == some("bool");
459501
}
502+
503+
fn fold_impl(
504+
fold: fold::fold<astsrv::srv>,
505+
doc: doc::impldoc
506+
) -> doc::impldoc {
507+
508+
let srv = fold.ctxt;
509+
510+
let (iface_ty, self_ty) = astsrv::exec(srv) {|ctxt|
511+
alt ctxt.ast_map.get(doc.id) {
512+
ast_map::node_item(@{
513+
node: ast::item_impl(_, iface_ty, self_ty, _), _
514+
}) {
515+
let iface_ty = option::map(iface_ty) {|iface_ty|
516+
pprust::ty_to_str(iface_ty)
517+
};
518+
(iface_ty, some(pprust::ty_to_str(self_ty)))
519+
}
520+
_ { fail "expected impl" }
521+
}
522+
};
523+
524+
{
525+
iface_ty: iface_ty,
526+
self_ty: self_ty,
527+
methods: merge_methods(fold.ctxt, doc.id, doc.methods)
528+
with doc
529+
}
530+
}
531+
532+
#[test]
533+
fn should_add_impl_iface_ty() {
534+
let source = "impl i of j for int { fn a() { } }";
535+
let srv = astsrv::mk_srv_from_str(source);
536+
let doc = extract::from_srv(srv, "");
537+
let doc = run(srv, doc);
538+
assert doc.topmod.impls()[0].iface_ty == some("j");
539+
}
540+
541+
#[test]
542+
fn should_not_add_impl_iface_ty_if_none() {
543+
let source = "impl i for int { fn a() { } }";
544+
let srv = astsrv::mk_srv_from_str(source);
545+
let doc = extract::from_srv(srv, "");
546+
let doc = run(srv, doc);
547+
assert doc.topmod.impls()[0].iface_ty == none;
548+
}
549+
550+
#[test]
551+
fn should_add_impl_self_ty() {
552+
let source = "impl i for int { fn a() { } }";
553+
let srv = astsrv::mk_srv_from_str(source);
554+
let doc = extract::from_srv(srv, "");
555+
let doc = run(srv, doc);
556+
assert doc.topmod.impls()[0].self_ty == some("int");
557+
}
558+
559+
#[test]
560+
fn should_add_impl_method_sigs() {
561+
let source = "impl i for int { fn a() -> int { fail } }";
562+
let srv = astsrv::mk_srv_from_str(source);
563+
let doc = extract::from_srv(srv, "");
564+
let doc = run(srv, doc);
565+
assert doc.topmod.impls()[0].methods[0].sig == some("fn a() -> int");
566+
}
567+
568+
#[test]
569+
fn should_add_impl_method_ret_types() {
570+
let source = "impl i for int { fn a() -> int { fail } }";
571+
let srv = astsrv::mk_srv_from_str(source);
572+
let doc = extract::from_srv(srv, "");
573+
let doc = run(srv, doc);
574+
assert doc.topmod.impls()[0].methods[0].return.ty == some("int");
575+
}
576+
577+
#[test]
578+
fn should_not_add_impl_method_nil_ret_type() {
579+
let source = "impl i for int { fn a() { } }";
580+
let srv = astsrv::mk_srv_from_str(source);
581+
let doc = extract::from_srv(srv, "");
582+
let doc = run(srv, doc);
583+
assert doc.topmod.impls()[0].methods[0].return.ty == none;
584+
}
585+
586+
#[test]
587+
fn should_add_impl_method_arg_types() {
588+
let source = "impl i for int { fn a(b: int, c: bool) { } }";
589+
let srv = astsrv::mk_srv_from_str(source);
590+
let doc = extract::from_srv(srv, "");
591+
let doc = run(srv, doc);
592+
let fn_ = doc.topmod.impls()[0].methods[0];
593+
assert fn_.args[0].ty == some("int");
594+
assert fn_.args[1].ty == some("bool");
595+
}

0 commit comments

Comments
 (0)