1//! Contains information about "passes", used to modify crate information during the documentation
2//! process.
34use self::Condition::*;
5use crate::clean;
6use crate::core::DocContext;
78mod stripper;
9pub(crate) use stripper::*;
1011mod strip_aliased_non_local;
12pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;
1314mod strip_hidden;
15pub(crate) use self::strip_hidden::STRIP_HIDDEN;
1617mod strip_private;
18pub(crate) use self::strip_private::STRIP_PRIVATE;
1920mod strip_priv_imports;
21pub(crate) use self::strip_priv_imports::STRIP_PRIV_IMPORTS;
2223mod propagate_doc_cfg;
24pub(crate) use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;
2526mod propagate_stability;
27pub(crate) use self::propagate_stability::PROPAGATE_STABILITY;
2829pub(crate) mod collect_intra_doc_links;
30pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;
3132mod check_doc_test_visibility;
33pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY;
3435mod collect_trait_impls;
36pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
3738mod calculate_doc_coverage;
39pub(crate) use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE;
4041mod lint;
42pub(crate) use self::lint::RUN_LINTS;
4344/// A single pass over the cleaned documentation.
45///
46/// Runs in the compiler context, so it has access to types and traits and the like.
47#[derive(Copy, Clone)]
48pub(crate) struct Pass {
49pub(crate) name: &'static str,
50pub(crate) run: Option<fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate>,
51pub(crate) description: &'static str,
52}
5354/// In a list of passes, a pass that may or may not need to be run depending on options.
55#[derive(Copy, Clone)]
56pub(crate) struct ConditionalPass {
57pub(crate) pass: Pass,
58pub(crate) condition: Condition,
59}
6061/// How to decide whether to run a conditional pass.
62#[derive(Copy, Clone)]
63pub(crate) enum Condition {
64 Always,
65/// When `--document-private-items` is passed.
66WhenDocumentPrivate,
67/// When `--document-private-items` is not passed.
68WhenNotDocumentPrivate,
69/// When `--document-hidden-items` is not passed.
70WhenNotDocumentHidden,
71}
7273/// The full list of passes.
74pub(crate) const PASSES: &[Pass] = &[
75 CHECK_DOC_TEST_VISIBILITY,
76 STRIP_ALIASED_NON_LOCAL,
77 STRIP_HIDDEN,
78 STRIP_PRIVATE,
79 STRIP_PRIV_IMPORTS,
80 PROPAGATE_DOC_CFG,
81 PROPAGATE_STABILITY,
82 COLLECT_INTRA_DOC_LINKS,
83 COLLECT_TRAIT_IMPLS,
84 CALCULATE_DOC_COVERAGE,
85 RUN_LINTS,
86];
8788/// The list of passes run by default.
89pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
90 ConditionalPass::always(COLLECT_TRAIT_IMPLS),
91 ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
92 ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
93 ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
94 ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
95 ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
96 ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
97 ConditionalPass::always(PROPAGATE_DOC_CFG),
98 ConditionalPass::always(PROPAGATE_STABILITY),
99 ConditionalPass::always(RUN_LINTS),
100];
101102/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
103pub(crate) const COVERAGE_PASSES: &[ConditionalPass] = &[
104 ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
105 ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
106 ConditionalPass::always(CALCULATE_DOC_COVERAGE),
107];
108109impl ConditionalPass {
110pub(crate) const fn always(pass: Pass) -> Self {
111Self::new(pass, Always)
112 }
113114pub(crate) const fn new(pass: Pass, condition: Condition) -> Self {
115 ConditionalPass { pass, condition }
116 }
117}
118119/// Returns the given default set of passes.
120pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] {
121if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES }
122}