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