@@ -23,7 +23,8 @@ fn run(
23
23
fold_const: fold_const,
24
24
fold_enum: fold_enum,
25
25
fold_res: fold_res,
26
- fold_iface: fold_iface
26
+ fold_iface: fold_iface,
27
+ fold_impl: fold_impl
27
28
with * fold:: default_seq_fold ( ctxt)
28
29
} ) ;
29
30
fold. fold_crate ( fold, doc)
@@ -84,6 +85,14 @@ fn fold_mod(
84
85
none
85
86
}
86
87
}
88
+ doc:: impltag ( impldoc) {
89
+ let doc = fold. fold_impl ( fold, impldoc) ;
90
+ if fold. ctxt . have_docs {
91
+ some ( doc:: impltag ( doc) )
92
+ } else {
93
+ none
94
+ }
95
+ }
87
96
_ { some( itemtag) }
88
97
}
89
98
}
@@ -286,28 +295,35 @@ fn fold_iface(
286
295
) -> doc:: ifacedoc {
287
296
let doc = fold:: default_seq_fold_iface ( fold, doc) ;
288
297
let doc = {
289
- methods: vec:: map ( doc. methods ) { |doc|
290
- {
291
- args: prune_args ( doc. args ) ,
292
- return : prune_return ( doc. return )
293
- with doc
294
- }
295
- }
298
+ methods: prune_methods ( doc. methods )
296
299
with doc
297
300
} ;
298
- let methods_have_docs = vec:: foldl ( false , doc. methods ) { |accum, doc|
301
+ fold. ctxt . have_docs =
302
+ doc. brief != none
303
+ || doc. desc != none
304
+ || methods_have_docs ( doc. methods ) ;
305
+ ret doc;
306
+ }
307
+
308
+ fn prune_methods ( docs : [ doc:: methoddoc ] ) -> [ doc:: methoddoc ] {
309
+ vec:: map ( docs) { |doc|
310
+ {
311
+ args: prune_args ( doc. args ) ,
312
+ return : prune_return ( doc. return )
313
+ with doc
314
+ }
315
+ }
316
+ }
317
+
318
+ fn methods_have_docs ( docs : [ doc:: methoddoc ] ) -> bool {
319
+ vec:: foldl ( false , docs) { |accum, doc|
299
320
accum
300
321
|| doc. brief != none
301
322
|| doc. desc != none
302
323
|| vec:: is_not_empty ( doc. args )
303
324
|| doc. return . desc != none
304
325
|| doc. failure != none
305
- } ;
306
- fold. ctxt . have_docs =
307
- doc. brief != none
308
- || doc. desc != none
309
- || methods_have_docs;
310
- ret doc;
326
+ }
311
327
}
312
328
313
329
#[ test]
@@ -329,23 +345,77 @@ fn should_not_elide_ifaces_with_documented_methods() {
329
345
}
330
346
331
347
#[ test]
332
- fn should_not_elide_undocumented_methods ( ) {
348
+ fn should_not_elide_undocumented_iface_methods ( ) {
333
349
let doc = test:: mk_doc ( "#[doc = \" hey\" ] iface i { fn a(); }" ) ;
334
350
assert vec:: is_not_empty ( doc. topmod . ifaces ( ) [ 0 ] . methods ) ;
335
351
}
336
352
337
353
#[ test]
338
- fn should_elide_undocumented_method_args ( ) {
354
+ fn should_elide_undocumented_iface_method_args ( ) {
339
355
let doc = test:: mk_doc ( "#[doc = \" hey\" ] iface i { fn a(); }" ) ;
340
356
assert vec:: is_empty ( doc. topmod . ifaces ( ) [ 0 ] . methods [ 0 ] . args ) ;
341
357
}
342
358
343
359
#[ test]
344
- fn should_elide_undocumented_method_return_values ( ) {
360
+ fn should_elide_undocumented_iface_method_return_values ( ) {
345
361
let doc = test:: mk_doc ( "#[doc = \" hey\" ] iface i { fn a() -> int; }" ) ;
346
362
assert doc. topmod . ifaces ( ) [ 0 ] . methods [ 0 ] . return . ty == none;
347
363
}
348
364
365
+ fn fold_impl (
366
+ fold : fold:: fold < ctxt > ,
367
+ doc : doc:: impldoc
368
+ ) -> doc:: impldoc {
369
+ let doc = fold:: default_seq_fold_impl ( fold, doc) ;
370
+ let doc = {
371
+ methods: prune_methods ( doc. methods )
372
+ with doc
373
+ } ;
374
+ fold. ctxt . have_docs =
375
+ doc. brief != none
376
+ || doc. desc != none
377
+ || methods_have_docs ( doc. methods ) ;
378
+ ret doc;
379
+ }
380
+
381
+ #[ test]
382
+ fn should_elide_undocumented_impls ( ) {
383
+ let doc = test:: mk_doc ( "impl i for int { fn a() { } }" ) ;
384
+ assert vec:: is_empty ( doc. topmod . impls ( ) ) ;
385
+ }
386
+
387
+ #[ test]
388
+ fn should_not_elide_documented_impls ( ) {
389
+ let doc = test:: mk_doc ( "#[doc = \" hey\" ] impl i for int { fn a() { } }" ) ;
390
+ assert vec:: is_not_empty ( doc. topmod . impls ( ) ) ;
391
+ }
392
+
393
+ #[ test]
394
+ fn should_not_elide_impls_with_documented_methods ( ) {
395
+ let doc = test:: mk_doc ( "impl i for int { #[doc = \" hey\" ] fn a() { } }" ) ;
396
+ assert vec:: is_not_empty ( doc. topmod . impls ( ) ) ;
397
+ }
398
+
399
+ #[ test]
400
+ fn should_not_elide_undocumented_impl_methods ( ) {
401
+ let doc = test:: mk_doc ( "#[doc = \" hey\" ] impl i for int { fn a() { } }" ) ;
402
+ assert vec:: is_not_empty ( doc. topmod . impls ( ) [ 0 ] . methods ) ;
403
+ }
404
+
405
+ #[ test]
406
+ fn should_elide_undocumented_impl_method_args ( ) {
407
+ let doc = test:: mk_doc (
408
+ "#[doc = \" hey\" ] impl i for int { fn a(b: bool) { } }" ) ;
409
+ assert vec:: is_empty ( doc. topmod . impls ( ) [ 0 ] . methods [ 0 ] . args ) ;
410
+ }
411
+
412
+ #[ test]
413
+ fn should_elide_undocumented_impl_method_return_values ( ) {
414
+ let doc = test:: mk_doc (
415
+ "#[doc = \" hey\" ] impl i for int { fn a() -> int { } }" ) ;
416
+ assert doc. topmod . impls ( ) [ 0 ] . methods [ 0 ] . return . ty == none;
417
+ }
418
+
349
419
#[ cfg( test) ]
350
420
mod test {
351
421
fn mk_doc ( source : str ) -> doc:: cratedoc {
0 commit comments