rustdoc/passes/
strip_private.rs

1//! Strip all private items from the output. Additionally implies strip_priv_imports.
2//! Basically, the goal is to remove items that are not relevant for public documentation.
3
4use crate::clean::{self, ItemIdSet};
5use crate::core::DocContext;
6use crate::fold::DocFolder;
7use crate::passes::{ImplStripper, ImportStripper, Pass, Stripper};
8
9pub(crate) const STRIP_PRIVATE: Pass = Pass {
10    name: "strip-private",
11    run: Some(strip_private),
12    description: "strips all private items from a crate which cannot be seen externally, \
13                  implies strip-priv-imports",
14};
15
16/// Strip private items from the point of view of a crate or externally from a
17/// crate, specified by the `xcrate` flag.
18pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
19    // This stripper collects all *retained* nodes.
20    let mut retained = ItemIdSet::default();
21    let is_json_output = cx.is_json_output();
22
23    // strip all private items
24    {
25        let mut stripper = Stripper {
26            retained: &mut retained,
27            effective_visibilities: &cx.cache.effective_visibilities,
28            update_retained: true,
29            is_json_output,
30            tcx: cx.tcx,
31        };
32        krate = ImportStripper {
33            tcx: cx.tcx,
34            is_json_output,
35            document_hidden: cx.render_options.document_hidden,
36        }
37        .fold_crate(stripper.fold_crate(krate));
38    }
39
40    // strip all impls referencing private items
41    let mut stripper = ImplStripper {
42        tcx: cx.tcx,
43        retained: &retained,
44        cache: &cx.cache,
45        is_json_output,
46        document_private: cx.render_options.document_private,
47        document_hidden: cx.render_options.document_hidden,
48    };
49    stripper.fold_crate(krate)
50}