@@ -400,11 +400,15 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
400
400
401
401
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
402
402
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
403
- let Some ( headers) = check_attrs ( cx, & self . valid_idents , attrs) else {
403
+ let Some ( DocInfo {
404
+ empty,
405
+ doc_headers : headers,
406
+ } ) = check_attrs ( cx, & self . valid_idents , attrs)
407
+ else {
404
408
return ;
405
409
} ;
406
410
407
- if headers . empty && !item. span . is_dummy ( ) {
411
+ if empty && !item. span . is_dummy ( ) {
408
412
empty_docs:: check ( cx, attrs) ;
409
413
}
410
414
@@ -455,7 +459,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
455
459
456
460
fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: TraitItem < ' _ > ) {
457
461
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
458
- let Some ( headers) = check_attrs ( cx, & self . valid_idents , attrs) else {
462
+ let Some ( DocInfo {
463
+ empty : _,
464
+ doc_headers : headers,
465
+ } ) = check_attrs ( cx, & self . valid_idents , attrs)
466
+ else {
459
467
return ;
460
468
} ;
461
469
if let hir:: TraitItemKind :: Fn ( ref sig, ..) = item. kind {
@@ -467,7 +475,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
467
475
468
476
fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: ImplItem < ' _ > ) {
469
477
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
470
- let Some ( headers) = check_attrs ( cx, & self . valid_idents , attrs) else {
478
+ let Some ( DocInfo {
479
+ empty : _,
480
+ doc_headers : headers,
481
+ } ) = check_attrs ( cx, & self . valid_idents , attrs)
482
+ else {
471
483
return ;
472
484
} ;
473
485
if self . in_trait_impl || in_external_macro ( cx. tcx . sess , item. span ) {
@@ -507,7 +519,12 @@ struct DocHeaders {
507
519
safety : bool ,
508
520
errors : bool ,
509
521
panics : bool ,
522
+ }
523
+
524
+ #[ derive( Copy , Clone , Default ) ]
525
+ struct DocInfo {
510
526
empty : bool ,
527
+ doc_headers : DocHeaders ,
511
528
}
512
529
513
530
/// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and
@@ -517,7 +534,7 @@ struct DocHeaders {
517
534
/// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
518
535
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
519
536
/// "Panics" sections.
520
- fn check_attrs ( cx : & LateContext < ' _ > , valid_idents : & FxHashSet < String > , attrs : & [ Attribute ] ) -> Option < DocHeaders > {
537
+ fn check_attrs ( cx : & LateContext < ' _ > , valid_idents : & FxHashSet < String > , attrs : & [ Attribute ] ) -> Option < DocInfo > {
521
538
/// We don't want the parser to choke on intra doc links. Since we don't
522
539
/// actually care about rendering them, just pretend that all broken links
523
540
/// point to a fake address.
@@ -542,11 +559,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
542
559
. trim ( )
543
560
. to_string ( ) ;
544
561
doc. pop ( ) ;
545
-
546
562
if doc. is_empty ( ) {
547
- return Some ( DocHeaders {
563
+ return Some ( DocInfo {
548
564
empty : true ,
549
- .. DocHeaders :: default ( )
565
+ doc_headers : DocHeaders :: default ( ) ,
550
566
} ) ;
551
567
}
552
568
@@ -556,15 +572,18 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
556
572
let opts = main_body_opts ( ) - Options :: ENABLE_SMART_PUNCTUATION ;
557
573
let parser = pulldown_cmark:: Parser :: new_with_broken_link_callback ( & doc, opts, Some ( & mut cb) ) ;
558
574
559
- Some ( check_doc (
560
- cx,
561
- valid_idents,
562
- parser. into_offset_iter ( ) ,
563
- Fragments {
564
- fragments : & fragments,
565
- doc : & doc,
566
- } ,
567
- ) )
575
+ Some ( DocInfo {
576
+ empty : false ,
577
+ doc_headers : check_doc (
578
+ cx,
579
+ valid_idents,
580
+ parser. into_offset_iter ( ) ,
581
+ Fragments {
582
+ fragments : & fragments,
583
+ doc : & doc,
584
+ } ,
585
+ ) ,
586
+ } )
568
587
}
569
588
570
589
const RUST_CODE : & [ & str ] = & [ "rust" , "no_run" , "should_panic" , "compile_fail" ] ;
0 commit comments