@@ -26,7 +26,8 @@ fn run(
26
26
fold_const: fold_const,
27
27
fold_enum: fold_enum,
28
28
fold_res: fold_res,
29
- fold_iface: fold_iface
29
+ fold_iface: fold_iface,
30
+ fold_impl: fold_impl
30
31
with * fold:: default_seq_fold ( srv)
31
32
} ) ;
32
33
fold. fold_crate ( fold, doc)
@@ -398,9 +399,14 @@ fn merge_method_attrs(
398
399
( method. ident , attr_parser:: parse_method ( method. attrs ) )
399
400
}
400
401
}
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
+ }
403
408
}
409
+ _ { fail "unexpected item" }
404
410
}
405
411
} ;
406
412
@@ -448,3 +454,50 @@ fn should_extract_iface_method_docs() {
448
454
assert doc. topmod . ifaces ( ) [ 0 ] . methods [ 0 ] . return . desc == some ( "return" ) ;
449
455
assert doc. topmod . ifaces ( ) [ 0 ] . methods [ 0 ] . failure == some ( "failure" ) ;
450
456
}
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