]> git.proxmox.com Git - rustc.git/blame - src/librustdoc/passes/strip_private.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / librustdoc / passes / strip_private.rs
CommitLineData
dfeec247 1use rustc_hir::def_id::DefIdSet;
9e0c209e 2
9fa01778 3use crate::clean;
9fa01778 4use crate::core::DocContext;
60c5eb7d
XL
5use crate::fold::DocFolder;
6use crate::passes::{ImplStripper, ImportStripper, Pass, Stripper};
b7449926 7
fc512014 8crate const STRIP_PRIVATE: Pass = Pass {
532ac7d7 9 name: "strip-private",
60c5eb7d 10 run: strip_private,
532ac7d7 11 description: "strips all private items from a crate which cannot be seen externally, \
1b1a35ee 12 implies strip-priv-imports",
532ac7d7 13};
9e0c209e
SL
14
15/// Strip private items from the point of view of a crate or externally from a
16/// crate, specified by the `xcrate` flag.
6a06907d 17crate fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
9e0c209e 18 // This stripper collects all *retained* nodes.
a1dfa0c6 19 let mut retained = DefIdSet::default();
9e0c209e
SL
20
21 // strip all private items
22 {
23 let mut stripper = Stripper {
24 retained: &mut retained,
6a06907d 25 access_levels: &cx.cache.access_levels,
9e0c209e
SL
26 update_retained: true,
27 };
28 krate = ImportStripper.fold_crate(stripper.fold_crate(krate));
29 }
30
31 // strip all impls referencing private items
32 let mut stripper = ImplStripper { retained: &retained };
33 stripper.fold_crate(krate)
34}