@@ -524,7 +524,7 @@ impl CheckAttrVisitor<'tcx> {
524
524
. struct_span_err (
525
525
meta. span ( ) ,
526
526
& format ! (
527
- "`#![doc({} = \" ...\" )]` isn't allowed as a crate level attribute" ,
527
+ "`#![doc({} = \" ...\" )]` isn't allowed as a crate- level attribute" ,
528
528
attr_name,
529
529
) ,
530
530
)
@@ -535,79 +535,97 @@ impl CheckAttrVisitor<'tcx> {
535
535
}
536
536
537
537
fn check_doc_attrs ( & self , attr : & Attribute , hir_id : HirId , target : Target ) -> bool {
538
- if let Some ( mi) = attr. meta ( ) {
539
- if let Some ( list) = mi. meta_item_list ( ) {
540
- for meta in list {
541
- if meta. has_name ( sym:: alias) {
542
- if !self . check_attr_crate_level ( meta, hir_id, "alias" )
543
- || !self . check_doc_alias ( meta, hir_id, target)
538
+ let mut is_valid = true ;
539
+
540
+ if let Some ( list) = attr. meta ( ) . and_then ( |mi| mi. meta_item_list ( ) . map ( |l| l. to_vec ( ) ) ) {
541
+ for meta in list {
542
+ if let Some ( i_meta) = meta. meta_item ( ) {
543
+ match i_meta. name_or_empty ( ) {
544
+ sym:: alias
545
+ if !self . check_attr_crate_level ( & meta, hir_id, "alias" )
546
+ || !self . check_doc_alias ( & meta, hir_id, target) =>
544
547
{
545
- return false ;
548
+ is_valid = false
546
549
}
547
- } else if meta. has_name ( sym:: keyword) {
548
- if !self . check_attr_crate_level ( meta, hir_id, "keyword" )
549
- || !self . check_doc_keyword ( meta, hir_id)
550
+
551
+ sym:: keyword
552
+ if !self . check_attr_crate_level ( & meta, hir_id, "keyword" )
553
+ || !self . check_doc_keyword ( & meta, hir_id) =>
550
554
{
551
- return false ;
555
+ is_valid = false
552
556
}
553
- } else if meta . has_name ( sym :: test ) {
554
- if CRATE_HIR_ID != hir_id {
557
+
558
+ sym :: test if CRATE_HIR_ID != hir_id => {
555
559
self . tcx . struct_span_lint_hir (
556
560
INVALID_DOC_ATTRIBUTES ,
557
561
hir_id,
558
562
meta. span ( ) ,
559
563
|lint| {
560
564
lint. build (
561
- "`#![doc(test(...)]` is only allowed as a crate level attribute"
565
+ "`#![doc(test(...)]` is only allowed \
566
+ as a crate-level attribute",
562
567
)
563
568
. emit ( ) ;
564
569
} ,
565
570
) ;
566
- return false ;
571
+ is_valid = false ;
567
572
}
568
- } else if let Some ( i_meta) = meta. meta_item ( ) {
569
- if ![
570
- sym:: cfg,
571
- sym:: hidden,
572
- sym:: html_favicon_url,
573
- sym:: html_logo_url,
574
- sym:: html_no_source,
575
- sym:: html_playground_url,
576
- sym:: html_root_url,
577
- sym:: include,
578
- sym:: inline,
579
- sym:: issue_tracker_base_url,
580
- sym:: masked,
581
- sym:: no_default_passes, // deprecated
582
- sym:: no_inline,
583
- sym:: passes, // deprecated
584
- sym:: plugins, // removed, but rustdoc warns about it itself
585
- sym:: primitive,
586
- sym:: spotlight,
587
- sym:: test,
588
- ]
589
- . iter ( )
590
- . any ( |m| i_meta. has_name ( * m) )
591
- {
573
+
574
+ // no_default_passes: deprecated
575
+ // passes: deprecated
576
+ // plugins: removed, but rustdoc warns about it itself
577
+ sym:: alias
578
+ | sym:: cfg
579
+ | sym:: hidden
580
+ | sym:: html_favicon_url
581
+ | sym:: html_logo_url
582
+ | sym:: html_no_source
583
+ | sym:: html_playground_url
584
+ | sym:: html_root_url
585
+ | sym:: include
586
+ | sym:: inline
587
+ | sym:: issue_tracker_base_url
588
+ | sym:: keyword
589
+ | sym:: masked
590
+ | sym:: no_default_passes
591
+ | sym:: no_inline
592
+ | sym:: passes
593
+ | sym:: plugins
594
+ | sym:: primitive
595
+ | sym:: spotlight
596
+ | sym:: test => { }
597
+
598
+ _ => {
592
599
self . tcx . struct_span_lint_hir (
593
600
INVALID_DOC_ATTRIBUTES ,
594
601
hir_id,
595
602
i_meta. span ,
596
603
|lint| {
597
- lint . build ( & format ! (
604
+ let msg = format ! (
598
605
"unknown `doc` attribute `{}`" ,
599
- i_meta. name_or_empty ( )
600
- ) )
601
- . emit ( ) ;
606
+ rustc_ast_pretty :: pprust :: path_to_string ( & i_meta. path ) ,
607
+ ) ;
608
+ lint . build ( & msg ) . emit ( ) ;
602
609
} ,
603
610
) ;
604
- return false ;
611
+ is_valid = false ;
605
612
}
606
613
}
614
+ } else {
615
+ self . tcx . struct_span_lint_hir (
616
+ INVALID_DOC_ATTRIBUTES ,
617
+ hir_id,
618
+ meta. span ( ) ,
619
+ |lint| {
620
+ lint. build ( & format ! ( "invalid `doc` attribute" ) ) . emit ( ) ;
621
+ } ,
622
+ ) ;
623
+ is_valid = false ;
607
624
}
608
625
}
609
626
}
610
- true
627
+
628
+ is_valid
611
629
}
612
630
613
631
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
0 commit comments