@@ -149,10 +149,9 @@ pub struct Cache {
149
149
150
150
/// This map contains information about all known traits of this crate.
151
151
/// Implementations of a crate should inherit the documentation of the
152
- /// parent trait if no extra documentation is specified, and this map is
153
- /// keyed on trait id with a value of a 'method name => documentation'
154
- /// mapping.
155
- traits : HashMap < ast:: NodeId , HashMap < ~str , ~str > > ,
152
+ /// parent trait if no extra documentation is specified, and default methods
153
+ /// should show up in documentation about trait implementations.
154
+ traits : HashMap < ast:: NodeId , clean:: Trait > ,
156
155
157
156
/// When rendering traits, it's often useful to be able to list all
158
157
/// implementors of the trait, and this mapping is exactly, that: a mapping
@@ -488,18 +487,7 @@ impl DocFolder for Cache {
488
487
// trait
489
488
match item. inner {
490
489
clean:: TraitItem ( ref t) => {
491
- let mut dox = HashMap :: new ( ) ;
492
- for meth in t. methods . iter ( ) {
493
- let it = meth. item ( ) ;
494
- match it. doc_value ( ) {
495
- None => { }
496
- Some ( s) => {
497
- dox. insert ( it. name . get_ref ( ) . to_owned ( ) ,
498
- s. to_owned ( ) ) ;
499
- }
500
- }
501
- }
502
- self . traits . insert ( item. id , dox) ;
490
+ self . traits . insert ( item. id , t. clone ( ) ) ;
503
491
}
504
492
_ => { }
505
493
}
@@ -1480,18 +1468,25 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
1480
1468
}
1481
1469
None => { }
1482
1470
}
1483
- write ! ( w , "<div class='methods'>" ) ;
1484
- for meth in i . methods . iter ( ) {
1471
+
1472
+ fn docmeth ( w : & mut io :: Writer , item : & clean :: Item ) -> bool {
1485
1473
write ! ( w, "<h4 id='method.{}' class='method'><code>" ,
1486
- * meth . name. get_ref( ) ) ;
1487
- render_method ( w, meth , false ) ;
1474
+ * item . name. get_ref( ) ) ;
1475
+ render_method ( w, item , false ) ;
1488
1476
write ! ( w, "</code></h4>\n " ) ;
1489
- match meth . doc_value ( ) {
1477
+ match item . doc_value ( ) {
1490
1478
Some ( s) => {
1491
1479
write ! ( w, "<div class='docblock'>{}</div>" , Markdown ( s) ) ;
1492
- continue
1480
+ true
1493
1481
}
1494
- None => { }
1482
+ None => false
1483
+ }
1484
+ }
1485
+
1486
+ write ! ( w, "<div class='methods'>" ) ;
1487
+ for meth in i. methods . iter ( ) {
1488
+ if docmeth ( w, meth) {
1489
+ continue
1495
1490
}
1496
1491
1497
1492
// No documentation? Attempt to slurp in the trait's documentation
@@ -1501,13 +1496,19 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
1501
1496
} ;
1502
1497
do local_data:: get ( cache_key) |cache| {
1503
1498
do cache. unwrap ( ) . read |cache| {
1504
- let name = meth. name . get_ref ( ) . as_slice ( ) ;
1505
1499
match cache. traits . find ( & trait_id) {
1506
- Some ( m) => {
1507
- match m. find_equiv ( & name) {
1508
- Some ( s) => {
1509
- write ! ( w, "<div class='docblock'>{}</div>" ,
1510
- Markdown ( s. as_slice( ) ) ) ;
1500
+ Some ( t) => {
1501
+ let name = meth. name . clone ( ) ;
1502
+ match t. methods . iter ( ) . find ( |t| t. item ( ) . name == name) {
1503
+ Some ( method) => {
1504
+ match method. item ( ) . doc_value ( ) {
1505
+ Some ( s) => {
1506
+ write ! ( w,
1507
+ "<div class='docblock'>{}</div>" ,
1508
+ Markdown ( s) ) ;
1509
+ }
1510
+ None => { }
1511
+ }
1511
1512
}
1512
1513
None => { }
1513
1514
}
@@ -1517,6 +1518,32 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl, dox: &Option<~str>) {
1517
1518
}
1518
1519
}
1519
1520
}
1521
+
1522
+ // If we've implemented a trait, then also emit documentation for all
1523
+ // default methods which weren't overridden in the implementation block.
1524
+ match trait_id {
1525
+ None => { }
1526
+ Some ( id) => {
1527
+ do local_data:: get ( cache_key) |cache| {
1528
+ do cache. unwrap ( ) . read |cache| {
1529
+ match cache. traits . find ( & id) {
1530
+ Some ( t) => {
1531
+ for method in t. methods . iter ( ) {
1532
+ let n = method. item ( ) . name . clone ( ) ;
1533
+ match i. methods . iter ( ) . find ( |m| m. name == n) {
1534
+ Some ( * ) => continue ,
1535
+ None => { }
1536
+ }
1537
+
1538
+ docmeth ( w, method. item ( ) ) ;
1539
+ }
1540
+ }
1541
+ None => { }
1542
+ }
1543
+ }
1544
+ }
1545
+ }
1546
+ }
1520
1547
write ! ( w, "</div>" ) ;
1521
1548
}
1522
1549
0 commit comments