1- #![ allow( dead_code, unused_imports) ]
2-
3- use rustc_hir:: HirId ;
1+ use rustc_attr_parsing:: { ShouldEmit , eval_config_entry} ;
2+ use rustc_hir:: attrs:: AttributeKind ;
43use rustc_hir:: def_id:: LocalDefId ;
4+ use rustc_hir:: { Attribute , HirId } ;
55use rustc_middle:: ty:: TyCtxt ;
6- use rustc_span:: sym;
76
87use super :: Pass ;
98use crate :: clean:: { Attributes , Crate , Item } ;
@@ -16,59 +15,58 @@ pub(crate) const CHECK_DOC_CFG: Pass = Pass {
1615 description : "checks `#[doc(cfg(...))]` for stability feature and unexpected cfgs" ,
1716} ;
1817
19- pub ( crate ) fn check_doc_cfg ( krate : Crate , _cx : & mut DocContext < ' _ > ) -> Crate {
20- // let mut checker = DocCfgChecker { cx };
21- // checker.visit_crate(&krate);
18+ pub ( crate ) fn check_doc_cfg ( krate : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
19+ let mut checker = DocCfgChecker { cx } ;
20+ checker. visit_crate ( & krate) ;
2221 krate
2322}
2423
25- // struct RustdocCfgMatchesLintEmitter<'a>(TyCtxt<'a>, HirId);
24+ struct RustdocCfgMatchesLintEmitter < ' a > ( TyCtxt < ' a > , HirId ) ;
2625
27- // impl<'a> rustc_attr_parsing::CfgMatchesLintEmitter for RustdocCfgMatchesLintEmitter<'a> {
28- // fn emit_span_lint(
29- // &self,
30- // sess: &rustc_session::Session,
31- // lint: &'static rustc_lint::Lint,
32- // sp: rustc_span::Span,
33- // builtin_diag: rustc_lint_defs::BuiltinLintDiag,
34- // ) {
35- // self.0.node_span_lint(lint, self.1, sp, |diag| {
36- // rustc_lint::decorate_builtin_lint(sess, Some(self.0), builtin_diag, diag)
37- // });
38- // }
39- // }
26+ impl < ' a > rustc_attr_parsing:: CfgMatchesLintEmitter for RustdocCfgMatchesLintEmitter < ' a > {
27+ fn emit_span_lint (
28+ & self ,
29+ sess : & rustc_session:: Session ,
30+ lint : & ' static rustc_lint:: Lint ,
31+ sp : rustc_span:: Span ,
32+ builtin_diag : rustc_lint_defs:: BuiltinLintDiag ,
33+ ) {
34+ self . 0 . node_span_lint ( lint, self . 1 , sp, |diag| {
35+ rustc_lint:: decorate_builtin_lint ( sess, Some ( self . 0 ) , builtin_diag, diag)
36+ } ) ;
37+ }
38+ }
4039
41- // struct DocCfgChecker<'a, 'tcx> {
42- // cx: &'a mut DocContext<'tcx>,
43- // }
40+ struct DocCfgChecker < ' a , ' tcx > {
41+ cx : & ' a mut DocContext < ' tcx > ,
42+ }
4443
45- // impl DocCfgChecker<'_, '_> {
46- // fn check_attrs(&mut self, attrs: &Attributes, did: LocalDefId) {
47- // for attr in &attrs.other_attrs {
48- // let Attribute::Parsed(AttributeKind::Doc(d)) = attr else { continue };
49- // let Some(doc_cfg) = d.cfg else { continue };
44+ impl DocCfgChecker < ' _ , ' _ > {
45+ fn check_attrs ( & mut self , attrs : & Attributes , did : LocalDefId ) {
46+ for attr in & attrs. other_attrs {
47+ let Attribute :: Parsed ( AttributeKind :: Doc ( d) ) = attr else { continue } ;
5048
51- // if let Some([cfg_mi]) = doc_cfg.meta_item_list() {
52- // let _ = rustc_attr_parsing::cfg_matches (
53- // cfg_mi ,
54- // &self.cx.tcx.sess ,
55- // RustdocCfgMatchesLintEmitter(
56- // self.cx.tcx,
57- // self.cx.tcx.local_def_id_to_hir_id(did),
58- // ),
59- // Some(self.cx.tcx.features()) ,
60- // );
61- // }
62- // }
63- // }
64- // }
49+ for doc_cfg in & d . cfg {
50+ let _ = eval_config_entry (
51+ & self . cx . tcx . sess ,
52+ doc_cfg ,
53+ & RustdocCfgMatchesLintEmitter (
54+ self . cx . tcx ,
55+ self . cx . tcx . local_def_id_to_hir_id ( did) ,
56+ ) ,
57+ ShouldEmit :: ErrorsAndLints ,
58+ ) ;
59+ }
60+ }
61+ }
62+ }
6563
66- // impl DocVisitor<'_> for DocCfgChecker<'_, '_> {
67- // fn visit_item(&mut self, item: &'_ Item) {
68- // if let Some(Some(local_did)) = item.def_id().map(|did| did.as_local()) {
69- // self.check_attrs(&item.attrs, local_did);
70- // }
64+ impl DocVisitor < ' _ > for DocCfgChecker < ' _ , ' _ > {
65+ fn visit_item ( & mut self , item : & ' _ Item ) {
66+ if let Some ( Some ( local_did) ) = item. def_id ( ) . map ( |did| did. as_local ( ) ) {
67+ self . check_attrs ( & item. attrs , local_did) ;
68+ }
7169
72- // self.visit_item_recur(item);
73- // }
74- // }
70+ self . visit_item_recur ( item) ;
71+ }
72+ }
0 commit comments