@@ -10,8 +10,9 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1010use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
1111use rustc_hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE , LocalDefId } ;
1212use rustc_hir:: lang_items:: LangItem ;
13- use rustc_hir:: { BodyId , Mutability } ;
13+ use rustc_hir:: { BodyId , HirId , Mutability } ;
1414use rustc_index:: IndexVec ;
15+ use rustc_lint_defs:: { BuiltinLintDiag , Lint } ;
1516use rustc_metadata:: rendered_const;
1617use rustc_middle:: span_bug;
1718use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
@@ -475,7 +476,12 @@ impl Item {
475476 name,
476477 kind,
477478 Attributes :: from_hir ( hir_attrs) ,
478- extract_cfg_from_attrs ( hir_attrs. iter ( ) , cx. tcx , & cx. cache . hidden_cfg ) ,
479+ extract_cfg_from_attrs (
480+ hir_attrs. iter ( ) ,
481+ cx. tcx ,
482+ def_id. as_local ( ) . map ( |did| cx. tcx . local_def_id_to_hir_id ( did) ) ,
483+ & cx. cache . hidden_cfg ,
484+ ) ,
479485 )
480486 }
481487
@@ -1014,6 +1020,7 @@ pub(crate) fn hir_attr_lists<'a, I: IntoIterator<Item = &'a hir::Attribute>>(
10141020pub ( crate ) fn extract_cfg_from_attrs < ' a , I : Iterator < Item = & ' a hir:: Attribute > + Clone > (
10151021 attrs : I ,
10161022 tcx : TyCtxt < ' _ > ,
1023+ hir_id : Option < HirId > ,
10171024 hidden_cfg : & FxHashSet < Cfg > ,
10181025) -> Option < Arc < Cfg > > {
10191026 let doc_cfg_active = tcx. features ( ) . doc_cfg ( ) ;
@@ -1037,6 +1044,32 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10371044 . peekable ( ) ;
10381045 if doc_cfg. peek ( ) . is_some ( ) && doc_cfg_active {
10391046 let sess = tcx. sess ;
1047+
1048+ struct RustdocCfgMatchesLintEmitter < ' a > ( TyCtxt < ' a > , Option < HirId > ) ;
1049+
1050+ impl < ' a > rustc_attr_parsing:: CfgMatchesLintEmitter for RustdocCfgMatchesLintEmitter < ' a > {
1051+ fn emit_span_lint (
1052+ & self ,
1053+ sess : & Session ,
1054+ lint : & ' static Lint ,
1055+ sp : rustc_span:: Span ,
1056+ builtin_diag : BuiltinLintDiag ,
1057+ ) {
1058+ if let Some ( hir_id) = self . 1 {
1059+ self . 0 . node_span_lint ( lint, hir_id, sp, |diag| {
1060+ rustc_lint:: decorate_builtin_lint (
1061+ sess,
1062+ Some ( self . 0 ) ,
1063+ builtin_diag,
1064+ diag,
1065+ )
1066+ } ) ;
1067+ } else {
1068+ // no HIR id, probably in another crate don't lint
1069+ }
1070+ }
1071+ }
1072+
10401073 doc_cfg. fold ( Cfg :: True , |mut cfg, item| {
10411074 if let Some ( cfg_mi) =
10421075 item. meta_item ( ) . and_then ( |item| rustc_expand:: config:: parse_cfg ( item, sess) )
@@ -1045,7 +1078,7 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10451078 rustc_attr_parsing:: cfg_matches (
10461079 cfg_mi,
10471080 tcx. sess ,
1048- rustc_ast :: CRATE_NODE_ID ,
1081+ RustdocCfgMatchesLintEmitter ( tcx , hir_id ) ,
10491082 Some ( tcx. features ( ) ) ,
10501083 ) ;
10511084 match Cfg :: parse ( cfg_mi) {
0 commit comments