Make MissingDoc a module lint.
This commit is contained in:
parent
53e5fd6a61
commit
7c34f1a8d8
9 changed files with 84 additions and 120 deletions
|
@ -457,10 +457,7 @@ declare_lint! {
|
|||
report_in_external_macro
|
||||
}
|
||||
|
||||
pub struct MissingDoc {
|
||||
/// Stack of whether `#[doc(hidden)]` is set at each level which has lint attributes.
|
||||
doc_hidden_stack: Vec<bool>,
|
||||
}
|
||||
pub struct MissingDoc;
|
||||
|
||||
impl_lint_pass!(MissingDoc => [MISSING_DOCS]);
|
||||
|
||||
|
@ -489,14 +486,6 @@ fn has_doc(attr: &ast::Attribute) -> bool {
|
|||
}
|
||||
|
||||
impl MissingDoc {
|
||||
pub fn new() -> MissingDoc {
|
||||
MissingDoc { doc_hidden_stack: vec![false] }
|
||||
}
|
||||
|
||||
fn doc_hidden(&self) -> bool {
|
||||
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
|
||||
}
|
||||
|
||||
fn check_missing_docs_attrs(
|
||||
&self,
|
||||
cx: &LateContext<'_>,
|
||||
|
@ -510,11 +499,6 @@ impl MissingDoc {
|
|||
return;
|
||||
}
|
||||
|
||||
// `#[doc(hidden)]` disables missing_docs check.
|
||||
if self.doc_hidden() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only check publicly-visible items, using the result from the privacy pass.
|
||||
// It's an option so the crate root can also use this function (it doesn't
|
||||
// have a `NodeId`).
|
||||
|
@ -537,23 +521,6 @@ impl MissingDoc {
|
|||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
#[inline]
|
||||
fn enter_lint_attrs(&mut self, _cx: &LateContext<'_>, attrs: &[ast::Attribute]) {
|
||||
let doc_hidden = self.doc_hidden()
|
||||
|| attrs.iter().any(|attr| {
|
||||
attr.has_name(sym::doc)
|
||||
&& match attr.meta_item_list() {
|
||||
None => false,
|
||||
Some(l) => attr::list_contains_name(&l, sym::hidden),
|
||||
}
|
||||
});
|
||||
self.doc_hidden_stack.push(doc_hidden);
|
||||
}
|
||||
|
||||
fn exit_lint_attrs(&mut self, _: &LateContext<'_>, _attrs: &[ast::Attribute]) {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
self.check_missing_docs_attrs(cx, CRATE_DEF_ID, "the", "crate");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::{join, DynSend};
|
||||
use rustc_data_structures::sync::join;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::intravisit as hir_visit;
|
||||
|
@ -336,7 +336,7 @@ macro_rules! impl_late_lint_pass {
|
|||
|
||||
crate::late_lint_methods!(impl_late_lint_pass, []);
|
||||
|
||||
pub(super) fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
||||
pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module_def_id: LocalDefId,
|
||||
builtin_lints: T,
|
||||
|
@ -376,6 +376,12 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
let mut cx = LateContextAndPass { context, pass };
|
||||
|
||||
let (module, _span, hir_id) = tcx.hir().get_module(module_def_id);
|
||||
|
||||
// There is no module lint that will have the crate itself as an item, so check it here.
|
||||
if hir_id == hir::CRATE_HIR_ID {
|
||||
lint_callback!(cx, check_crate,);
|
||||
}
|
||||
|
||||
cx.process_mod(module, hir_id);
|
||||
|
||||
// Visit the crate attributes
|
||||
|
@ -383,10 +389,19 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() {
|
||||
cx.visit_attribute(attr)
|
||||
}
|
||||
lint_callback!(cx, check_crate_post,);
|
||||
}
|
||||
}
|
||||
|
||||
fn late_lint_crate<'tcx, T: LateLintPass<'tcx> + 'tcx>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
|
||||
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
// Note: `passes` is often empty.
|
||||
let mut passes: Vec<_> =
|
||||
unerased_lint_store(tcx).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
|
||||
if passes.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let context = LateContext {
|
||||
tcx,
|
||||
enclosing_body: None,
|
||||
|
@ -399,18 +414,8 @@ fn late_lint_crate<'tcx, T: LateLintPass<'tcx> + 'tcx>(tcx: TyCtxt<'tcx>, builti
|
|||
only_module: false,
|
||||
};
|
||||
|
||||
// Note: `passes` is often empty. In that case, it's faster to run
|
||||
// `builtin_lints` directly rather than bundling it up into the
|
||||
// `RuntimeCombinedLateLintPass`.
|
||||
let mut passes: Vec<_> =
|
||||
unerased_lint_store(tcx).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
if passes.is_empty() {
|
||||
late_lint_crate_inner(tcx, context, builtin_lints);
|
||||
} else {
|
||||
passes.push(Box::new(builtin_lints));
|
||||
let pass = RuntimeCombinedLateLintPass { passes: &mut passes[..] };
|
||||
late_lint_crate_inner(tcx, context, pass);
|
||||
}
|
||||
let pass = RuntimeCombinedLateLintPass { passes: &mut passes[..] };
|
||||
late_lint_crate_inner(tcx, context, pass);
|
||||
}
|
||||
|
||||
fn late_lint_crate_inner<'tcx, T: LateLintPass<'tcx>>(
|
||||
|
@ -432,15 +437,12 @@ fn late_lint_crate_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
}
|
||||
|
||||
/// Performs lint checking on a crate.
|
||||
pub fn check_crate<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
builtin_lints: impl FnOnce() -> T + Send + DynSend,
|
||||
) {
|
||||
pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
join(
|
||||
|| {
|
||||
tcx.sess.time("crate_lints", || {
|
||||
// Run whole crate non-incremental lints
|
||||
late_lint_crate(tcx, builtin_lints());
|
||||
late_lint_crate(tcx);
|
||||
});
|
||||
},
|
||||
|| {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::{
|
||||
builtin::MISSING_DOCS,
|
||||
context::{CheckLintNameResult, LintStore},
|
||||
fluent_generated as fluent,
|
||||
late::unerased_lint_store,
|
||||
|
@ -667,6 +668,16 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
continue;
|
||||
}
|
||||
|
||||
// `#[doc(hidden)]` disables missing_docs check.
|
||||
if attr.has_name(sym::doc)
|
||||
&& attr
|
||||
.meta_item_list()
|
||||
.map_or(false, |l| ast::attr::list_contains_name(&l, sym::hidden))
|
||||
{
|
||||
self.insert(LintId::of(MISSING_DOCS), (Level::Allow, LintLevelSource::Default));
|
||||
continue;
|
||||
}
|
||||
|
||||
let level = match Level::from_attr(attr) {
|
||||
None => continue,
|
||||
// This is the only lint level with a `LintExpectationId` that can be created from an attribute
|
||||
|
|
|
@ -126,11 +126,11 @@ use types::*;
|
|||
use unused::*;
|
||||
|
||||
/// Useful for other parts of the compiler / Clippy.
|
||||
pub use builtin::SoftLints;
|
||||
pub use builtin::{MissingDoc, SoftLints};
|
||||
pub use context::{CheckLintNameResult, FindLintError, LintStore};
|
||||
pub use context::{EarlyContext, LateContext, LintContext};
|
||||
pub use early::{check_ast_node, EarlyCheckNode};
|
||||
pub use late::{check_crate, unerased_lint_store};
|
||||
pub use late::{check_crate, late_lint_mod, unerased_lint_store};
|
||||
pub use passes::{EarlyLintPass, LateLintPass};
|
||||
pub use rustc_session::lint::Level::{self, *};
|
||||
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId};
|
||||
|
@ -146,7 +146,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
}
|
||||
|
||||
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
||||
late::late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
|
||||
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
|
||||
}
|
||||
|
||||
early_lint_methods!(
|
||||
|
@ -184,19 +184,6 @@ early_lint_methods!(
|
|||
]
|
||||
);
|
||||
|
||||
// FIXME: Make a separate lint type which does not require typeck tables.
|
||||
|
||||
late_lint_methods!(
|
||||
declare_combined_late_lint_pass,
|
||||
[
|
||||
pub BuiltinCombinedLateLintPass,
|
||||
[
|
||||
// Tracks attributes of parents
|
||||
MissingDoc: MissingDoc::new(),
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
late_lint_methods!(
|
||||
declare_combined_late_lint_pass,
|
||||
[
|
||||
|
@ -250,6 +237,7 @@ late_lint_methods!(
|
|||
MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
|
||||
MapUnitFn: MapUnitFn,
|
||||
MissingDebugImplementations: MissingDebugImplementations,
|
||||
MissingDoc: MissingDoc,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
@ -278,7 +266,6 @@ fn register_builtins(store: &mut LintStore) {
|
|||
store.register_lints(&BuiltinCombinedPreExpansionLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedLateLintPass::get_lints());
|
||||
store.register_lints(&foreign_modules::get_lints());
|
||||
|
||||
add_lint_group!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue