@@ -524,7 +524,7 @@ impl CheckAttrVisitor<'tcx> {
524524 . struct_span_err (
525525 meta. span ( ) ,
526526 & format ! (
527- "`#![doc({} = \" ...\" )]` isn't allowed as a crate level attribute" ,
527+ "`#![doc({} = \" ...\" )]` isn't allowed as a crate- level attribute" ,
528528 attr_name,
529529 ) ,
530530 )
@@ -535,79 +535,97 @@ impl CheckAttrVisitor<'tcx> {
535535 }
536536
537537 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) =>
544547 {
545- return false ;
548+ is_valid = false
546549 }
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) =>
550554 {
551- return false ;
555+ is_valid = false
552556 }
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 => {
555559 self . tcx . struct_span_lint_hir (
556560 INVALID_DOC_ATTRIBUTES ,
557561 hir_id,
558562 meta. span ( ) ,
559563 |lint| {
560564 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",
562567 )
563568 . emit ( ) ;
564569 } ,
565570 ) ;
566- return false ;
571+ is_valid = false ;
567572 }
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+ _ => {
592599 self . tcx . struct_span_lint_hir (
593600 INVALID_DOC_ATTRIBUTES ,
594601 hir_id,
595602 i_meta. span ,
596603 |lint| {
597- lint . build ( & format ! (
604+ let msg = format ! (
598605 "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 ( ) ;
602609 } ,
603610 ) ;
604- return false ;
611+ is_valid = false ;
605612 }
606613 }
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 ;
607624 }
608625 }
609626 }
610- true
627+
628+ is_valid
611629 }
612630
613631 /// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
0 commit comments