]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/passes/strip_private.rs
Rollup merge of #104317 - RalfJung:ctfe-error-reporting, r=oli-obk
[rust.git] / src / librustdoc / 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 use crate::clean::{self, ItemIdSet};
4 use crate::core::DocContext;
5 use crate::fold::DocFolder;
6 use crate::passes::{ImplStripper, ImportStripper, Pass, Stripper};
7
8 pub(crate) const STRIP_PRIVATE: Pass = Pass {
9     name: "strip-private",
10     run: strip_private,
11     description: "strips all private items from a crate which cannot be seen externally, \
12                   implies strip-priv-imports",
13 };
14
15 /// Strip private items from the point of view of a crate or externally from a
16 /// crate, specified by the `xcrate` flag.
17 pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
18     // This stripper collects all *retained* nodes.
19     let mut retained = ItemIdSet::default();
20     let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
21
22     // strip all private items
23     {
24         let mut stripper = Stripper {
25             retained: &mut retained,
26             effective_visibilities: &cx.cache.effective_visibilities,
27             update_retained: true,
28             is_json_output,
29             tcx: cx.tcx,
30         };
31         krate = ImportStripper { tcx: cx.tcx }.fold_crate(stripper.fold_crate(krate));
32     }
33
34     // strip all impls referencing private items
35     let mut stripper = ImplStripper {
36         tcx: cx.tcx,
37         retained: &retained,
38         cache: &cx.cache,
39         is_json_output,
40         document_private: cx.render_options.document_private,
41     };
42     stripper.fold_crate(krate)
43 }