1
Fork 0

Treat macros as HIR items

This commit is contained in:
inquisitivecrystal 2021-07-30 23:50:57 -07:00
parent ac50a53359
commit 8c62fa0575
31 changed files with 162 additions and 256 deletions

View file

@ -585,24 +585,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
self.check_missing_docs_attrs(cx, CRATE_DEF_ID, krate.module().inner, "the", "crate");
for macro_def in krate.exported_macros() {
// Non exported macros should be skipped, since `missing_docs` only
// applies to externally visible items.
if !cx.access_levels.is_exported(macro_def.def_id) {
continue;
}
let attrs = cx.tcx.hir().attrs(macro_def.hir_id());
let has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().guess_head_span(macro_def.span),
|lint| lint.build("missing documentation for macro").emit(),
);
}
}
}
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
@ -636,6 +618,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::TyAlias(..)
| hir::ItemKind::Fn(..)
| hir::ItemKind::Macro(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)

View file

@ -453,10 +453,6 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
lint_callback!(cx, check_crate, krate);
hir_visit::walk_crate(cx, krate);
for attr in krate.non_exported_macro_attrs {
// This HIR ID is a lie, since the macro ID isn't available.
cx.visit_attribute(hir::CRATE_HIR_ID, attr);
}
lint_callback!(cx, check_crate_post, krate);
})

View file

@ -37,9 +37,6 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true);
builder.levels.register_id(hir::CRATE_HIR_ID);
for macro_def in krate.exported_macros() {
builder.levels.register_id(macro_def.hir_id());
}
intravisit::walk_crate(&mut builder, krate);
builder.levels.pop(push);