use self::Condition::*;
use crate::clean;
use crate::core::DocContext;
mod stripper;
pub(crate) use stripper::*;
mod strip_aliased_non_local;
pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;
mod strip_hidden;
pub(crate) use self::strip_hidden::STRIP_HIDDEN;
mod strip_private;
pub(crate) use self::strip_private::STRIP_PRIVATE;
mod strip_priv_imports;
pub(crate) use self::strip_priv_imports::STRIP_PRIV_IMPORTS;
mod propagate_doc_cfg;
pub(crate) use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;
mod propagate_stability;
pub(crate) use self::propagate_stability::PROPAGATE_STABILITY;
pub(crate) mod collect_intra_doc_links;
pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;
mod check_doc_test_visibility;
pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY;
mod collect_trait_impls;
pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
mod calculate_doc_coverage;
pub(crate) use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE;
mod lint;
pub(crate) use self::lint::RUN_LINTS;
#[derive(Copy, Clone)]
pub(crate) struct Pass {
pub(crate) name: &'static str,
pub(crate) run: Option<fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate>,
pub(crate) description: &'static str,
}
#[derive(Copy, Clone)]
pub(crate) struct ConditionalPass {
pub(crate) pass: Pass,
pub(crate) condition: Condition,
}
#[derive(Copy, Clone)]
pub(crate) enum Condition {
Always,
WhenDocumentPrivate,
WhenNotDocumentPrivate,
WhenNotDocumentHidden,
}
pub(crate) const PASSES: &[Pass] = &[
CHECK_DOC_TEST_VISIBILITY,
STRIP_ALIASED_NON_LOCAL,
STRIP_HIDDEN,
STRIP_PRIVATE,
STRIP_PRIV_IMPORTS,
PROPAGATE_DOC_CFG,
PROPAGATE_STABILITY,
COLLECT_INTRA_DOC_LINKS,
COLLECT_TRAIT_IMPLS,
CALCULATE_DOC_COVERAGE,
RUN_LINTS,
];
pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
ConditionalPass::always(PROPAGATE_DOC_CFG),
ConditionalPass::always(PROPAGATE_STABILITY),
ConditionalPass::always(RUN_LINTS),
];
pub(crate) const COVERAGE_PASSES: &[ConditionalPass] = &[
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
ConditionalPass::always(CALCULATE_DOC_COVERAGE),
];
impl ConditionalPass {
pub(crate) const fn always(pass: Pass) -> Self {
Self::new(pass, Always)
}
pub(crate) const fn new(pass: Pass, condition: Condition) -> Self {
ConditionalPass { pass, condition }
}
}
pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] {
if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES }
}