|
1 | 1 | //! Contains information about "passes", used to modify crate information during the documentation |
2 | 2 | //! process. |
3 | 3 |
|
4 | | -use self::Condition::*; |
5 | | -use crate::clean; |
6 | | -use crate::core::DocContext; |
7 | | - |
8 | 4 | mod stripper; |
9 | 5 | pub(crate) use stripper::*; |
10 | 6 |
|
11 | | -mod calculate_doc_coverage; |
12 | | -mod check_doc_cfg; |
13 | | -mod check_doc_test_visibility; |
| 7 | +pub(crate) mod calculate_doc_coverage; |
| 8 | +pub(crate) mod check_doc_cfg; |
| 9 | +pub(crate) mod check_doc_test_visibility; |
14 | 10 | pub(crate) mod collect_intra_doc_links; |
15 | | -mod collect_trait_impls; |
16 | | -mod lint; |
17 | | -mod propagate_doc_cfg; |
18 | | -mod propagate_stability; |
19 | | -mod strip_aliased_non_local; |
20 | | -mod strip_hidden; |
21 | | -mod strip_priv_imports; |
22 | | -mod strip_private; |
23 | | - |
24 | | -/// A single pass over the cleaned documentation. |
25 | | -/// |
26 | | -/// Runs in the compiler context, so it has access to types and traits and the like. |
27 | | -#[derive(Copy, Clone)] |
28 | | -pub(crate) struct Pass { |
29 | | - pub(crate) name: &'static str, |
30 | | - pub(crate) run: Option<fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate>, |
31 | | -} |
32 | | - |
33 | | -/// In a list of passes, a pass that may or may not need to be run depending on options. |
34 | | -#[derive(Copy, Clone)] |
35 | | -pub(crate) struct ConditionalPass { |
36 | | - pub(crate) pass: Pass, |
37 | | - pub(crate) condition: Condition, |
38 | | -} |
39 | | - |
40 | | -/// How to decide whether to run a conditional pass. |
41 | | -#[derive(Copy, Clone)] |
42 | | -pub(crate) enum Condition { |
43 | | - Always, |
44 | | - /// When `--document-private-items` is passed. |
45 | | - WhenDocumentPrivate, |
46 | | - /// When `--document-private-items` is not passed. |
47 | | - WhenNotDocumentPrivate, |
48 | | - /// When `--document-hidden-items` is not passed. |
49 | | - WhenNotDocumentHidden, |
50 | | -} |
51 | | - |
52 | | -/// The list of passes run by default. |
53 | | -const DEFAULT_PASSES: &[ConditionalPass] = &[ |
54 | | - ConditionalPass::always(collect_trait_impls::COLLECT_TRAIT_IMPLS), |
55 | | - ConditionalPass::always(check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY), |
56 | | - ConditionalPass::always(check_doc_cfg::CHECK_DOC_CFG), |
57 | | - ConditionalPass::always(strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL), |
58 | | - ConditionalPass::new(strip_hidden::STRIP_HIDDEN, WhenNotDocumentHidden), |
59 | | - ConditionalPass::new(strip_private::STRIP_PRIVATE, WhenNotDocumentPrivate), |
60 | | - ConditionalPass::new(strip_priv_imports::STRIP_PRIV_IMPORTS, WhenDocumentPrivate), |
61 | | - ConditionalPass::always(collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS), |
62 | | - ConditionalPass::always(propagate_doc_cfg::PROPAGATE_DOC_CFG), |
63 | | - ConditionalPass::always(propagate_stability::PROPAGATE_STABILITY), |
64 | | - ConditionalPass::always(lint::RUN_LINTS), |
65 | | -]; |
66 | | - |
67 | | -/// The list of default passes run when `--doc-coverage` is passed to rustdoc. |
68 | | -const COVERAGE_PASSES: &[ConditionalPass] = &[ |
69 | | - ConditionalPass::new(strip_hidden::STRIP_HIDDEN, WhenNotDocumentHidden), |
70 | | - ConditionalPass::new(strip_private::STRIP_PRIVATE, WhenNotDocumentPrivate), |
71 | | - ConditionalPass::always(calculate_doc_coverage::CALCULATE_DOC_COVERAGE), |
72 | | -]; |
73 | | - |
74 | | -impl ConditionalPass { |
75 | | - pub(crate) const fn always(pass: Pass) -> Self { |
76 | | - Self::new(pass, Always) |
77 | | - } |
78 | | - |
79 | | - pub(crate) const fn new(pass: Pass, condition: Condition) -> Self { |
80 | | - ConditionalPass { pass, condition } |
81 | | - } |
82 | | -} |
83 | | - |
84 | | -/// Returns the given default set of passes. |
85 | | -pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] { |
86 | | - if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES } |
87 | | -} |
| 11 | +pub(crate) mod collect_trait_impls; |
| 12 | +pub(crate) mod lint; |
| 13 | +pub(crate) mod propagate_doc_cfg; |
| 14 | +pub(crate) mod propagate_stability; |
| 15 | +pub(crate) mod strip_aliased_non_local; |
| 16 | +pub(crate) mod strip_hidden; |
| 17 | +pub(crate) mod strip_priv_imports; |
| 18 | +pub(crate) mod strip_private; |
| 19 | + |
| 20 | +pub(crate) macro track($tcx:expr, $name:ident($( $args:tt )*)) {{ |
| 21 | + tracing::debug!("running pass `{}`", stringify!($name)); |
| 22 | + $tcx.sess.time(stringify!($name), || self::$name::$name($( $args )*)) |
| 23 | +}} |
0 commit comments