Skip to main content

rustdoc/passes/
mod.rs

1//! The definitions of *passes* which transform crate information.
2
3use crate::clean::Crate;
4use crate::core::DocContext;
5
6mod stripper;
7pub(crate) use stripper::*;
8
9pub(crate) mod check_doc_test_visibility;
10pub(crate) mod collect_intra_doc_links;
11mod collect_trait_impls;
12mod lint;
13mod propagate_doc_cfg;
14mod propagate_stability;
15mod strip_aliased_non_local;
16mod strip_hidden;
17mod strip_priv_imports;
18mod strip_private;
19
20#[derive(Default)]
21pub(crate) struct Store {
22    links: collect_intra_doc_links::LinkCollection,
23}
24
25#[tracing::instrument(level = "info", skip_all)]
26pub(crate) fn run(
27    mut krate: Crate,
28    cx: &mut DocContext<'_>,
29    show_coverage: bool,
30) -> (Crate, Store) {
31    macro_rules! run {
32        ($name:ident($( $args:tt )*)) => {{
33            tracing::debug!("running pass `{}`", stringify!($name));
34            cx.tcx.sess.time(stringify!($name), || $name::$name($( $args )*))
35        }};
36    }
37
38    let mut store = Store::default();
39
40    if !show_coverage {
41        krate = run!(collect_trait_impls(krate, cx));
42        krate = run!(check_doc_test_visibility(krate, cx));
43        krate = run!(strip_aliased_non_local(krate, cx));
44        krate = run!(propagate_doc_cfg(krate, cx));
45    }
46
47    krate = run!(strip_hidden(krate, cx));
48    krate = run!(strip_private(krate, cx));
49
50    if !show_coverage {
51        krate = run!(strip_priv_imports(krate, cx));
52        (krate, store.links) = run!(collect_intra_doc_links(krate, cx));
53        krate = run!(propagate_stability(krate, cx));
54        krate = run!(lint(krate, cx));
55    }
56
57    (krate, store)
58}
59
60/// To be run after the cache in [`DocContext`] has been fully populated.
61pub(crate) fn finalize(cx: &mut DocContext<'_>, store: Store) {
62    collect_intra_doc_links::resolve_ambiguous_links(store.links, cx);
63}