@@ -297,6 +297,10 @@ struct Context {
297
297
// Just a simple flag if we're currently recursing into a trait
298
298
// implementation. This is only used by the lint_missing_doc() pass
299
299
in_trait_impl : bool ,
300
+ // Another flag for doc lint emissions. Does some parent of the current node
301
+ // have the doc(hidden) attribute? Treating this as allow(missing_doc) would
302
+ // play badly with forbid(missing_doc) when it shouldn't.
303
+ doc_hidden : bool ,
300
304
// When recursing into an attributed node of the ast which modifies lint
301
305
// levels, this stack keeps track of the previous lint levels of whatever
302
306
// was modified.
@@ -422,9 +426,30 @@ impl Context {
422
426
}
423
427
}
424
428
429
+ // detect doc(hidden)
430
+ let mut doc_hidden = false ;
431
+ for attr:: find_attrs_by_name( attrs, "doc" ) . each |attr| {
432
+ match attr:: get_meta_item_list ( attr. node . value ) {
433
+ Some ( s) => {
434
+ if attr:: find_meta_items_by_name ( s, "hidden" ) . len ( ) > 0 {
435
+ doc_hidden = true ;
436
+ }
437
+ }
438
+ None => { }
439
+ }
440
+ }
441
+ if doc_hidden && !self . doc_hidden {
442
+ self . doc_hidden = true ;
443
+ } else {
444
+ doc_hidden = false ;
445
+ }
446
+
425
447
f ( ) ;
426
448
427
449
// rollback
450
+ if doc_hidden && self . doc_hidden {
451
+ self . doc_hidden = false ;
452
+ }
428
453
for pushed. times {
429
454
let ( lint, lvl, src) = self . lint_stack. pop( ) ;
430
455
self . set_level( lint, lvl, src) ;
@@ -980,9 +1005,16 @@ fn lint_unnecessary_allocations() -> visit::vt<@mut Context> {
980
1005
fn lint_missing_doc( ) -> visit:: vt<@mut Context > {
981
1006
fn check_attrs ( cx : @mut Context , attrs : & [ ast:: attribute ] ,
982
1007
sp : span , msg : & str ) {
983
- if !attrs. any ( |a| a. node . is_sugared_doc ) {
984
- cx. span_lint ( missing_doc, sp, msg) ;
985
- }
1008
+ // If we're building a test harness, then warning about documentation is
1009
+ // probably not really relevant right now
1010
+ if cx. tcx . sess . opts . test { return }
1011
+ // If we have doc(hidden), nothing to do
1012
+ if cx. doc_hidden { return }
1013
+ // If we're documented, nothing to do
1014
+ if attrs. any ( |a| a. node . is_sugared_doc ) { return }
1015
+
1016
+ // otherwise, warn!
1017
+ cx. span_lint ( missing_doc, sp, msg) ;
986
1018
}
987
1019
988
1020
visit:: mk_vt ( @visit:: Visitor {
@@ -1067,6 +1099,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
1067
1099
lint_stack : ~[ ] ,
1068
1100
visitors : ~[ ] ,
1069
1101
in_trait_impl : false ,
1102
+ doc_hidden : false ,
1070
1103
} ;
1071
1104
1072
1105
// Install defaults.
0 commit comments