@@ -12,8 +12,9 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1212use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
1313use rustc_hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE , LocalDefId } ;
1414use rustc_hir:: lang_items:: LangItem ;
15- use rustc_hir:: { BodyId , Mutability } ;
15+ use rustc_hir:: { BodyId , HirId , Mutability } ;
1616use rustc_index:: IndexVec ;
17+ use rustc_lint_defs:: { BuiltinLintDiag , Lint } ;
1718use rustc_metadata:: rendered_const;
1819use rustc_middle:: span_bug;
1920use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
@@ -477,7 +478,12 @@ impl Item {
477478 name,
478479 kind,
479480 Attributes :: from_hir ( hir_attrs) ,
480- extract_cfg_from_attrs ( hir_attrs. iter ( ) , cx. tcx , & cx. cache . hidden_cfg ) ,
481+ extract_cfg_from_attrs (
482+ hir_attrs. iter ( ) ,
483+ cx. tcx ,
484+ def_id. as_local ( ) . map ( |did| cx. tcx . local_def_id_to_hir_id ( did) ) ,
485+ & cx. cache . hidden_cfg ,
486+ ) ,
481487 )
482488 }
483489
@@ -1033,6 +1039,7 @@ pub(crate) fn hir_attr_lists<'a, I: IntoIterator<Item = &'a hir::Attribute>>(
10331039pub ( crate ) fn extract_cfg_from_attrs < ' a , I : Iterator < Item = & ' a hir:: Attribute > + Clone > (
10341040 attrs : I ,
10351041 tcx : TyCtxt < ' _ > ,
1042+ hir_id : Option < HirId > ,
10361043 hidden_cfg : & FxHashSet < Cfg > ,
10371044) -> Option < Arc < Cfg > > {
10381045 let doc_cfg_active = tcx. features ( ) . doc_cfg ( ) ;
@@ -1056,6 +1063,32 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10561063 . peekable ( ) ;
10571064 if doc_cfg. peek ( ) . is_some ( ) && doc_cfg_active {
10581065 let sess = tcx. sess ;
1066+
1067+ struct RustdocCfgMatchesLintEmitter < ' a > ( TyCtxt < ' a > , Option < HirId > ) ;
1068+
1069+ impl < ' a > rustc_attr_parsing:: CfgMatchesLintEmitter for RustdocCfgMatchesLintEmitter < ' a > {
1070+ fn emit_span_lint (
1071+ & self ,
1072+ sess : & Session ,
1073+ lint : & ' static Lint ,
1074+ sp : rustc_span:: Span ,
1075+ builtin_diag : BuiltinLintDiag ,
1076+ ) {
1077+ if let Some ( hir_id) = self . 1 {
1078+ self . 0 . node_span_lint ( lint, hir_id, sp, |diag| {
1079+ rustc_lint:: decorate_builtin_lint (
1080+ sess,
1081+ Some ( self . 0 ) ,
1082+ builtin_diag,
1083+ diag,
1084+ )
1085+ } ) ;
1086+ } else {
1087+ // No HIR id. Probably in another crate. Don't lint.
1088+ }
1089+ }
1090+ }
1091+
10591092 doc_cfg. fold ( Cfg :: True , |mut cfg, item| {
10601093 if let Some ( cfg_mi) =
10611094 item. meta_item ( ) . and_then ( |item| rustc_expand:: config:: parse_cfg ( item, sess) )
@@ -1064,7 +1097,7 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10641097 rustc_attr_parsing:: cfg_matches (
10651098 cfg_mi,
10661099 tcx. sess ,
1067- rustc_ast :: CRATE_NODE_ID ,
1100+ RustdocCfgMatchesLintEmitter ( tcx , hir_id ) ,
10681101 Some ( tcx. features ( ) ) ,
10691102 ) ;
10701103 match Cfg :: parse ( cfg_mi) {
0 commit comments