Split out rustdoc pass to strip private imports
This commit is contained in:
parent
f6e125f04a
commit
688e52201e
5 changed files with 51 additions and 8 deletions
|
|
@ -107,6 +107,8 @@ const PASSES: &'static [Pass] = &[
|
|||
"concatenates all document attributes into one document attribute"),
|
||||
("strip-private", passes::strip_private,
|
||||
"strips all private items from a crate which cannot be seen externally"),
|
||||
("strip-priv-imports", passes::strip_priv_imports,
|
||||
"strips all private import statements (`use`, `extern crate`) from a crate"),
|
||||
];
|
||||
|
||||
const DEFAULT_PASSES: &'static [&'static str] = &[
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
|
|||
retained: &mut retained,
|
||||
access_levels: &access_levels,
|
||||
};
|
||||
krate = stripper.fold_crate(krate);
|
||||
krate = ImportStripper.fold_crate(stripper.fold_crate(krate));
|
||||
}
|
||||
|
||||
// strip all private implementations of traits
|
||||
|
|
@ -144,12 +144,6 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
clean::ExternCrateItem(..) | clean::ImportItem(_) => {
|
||||
if i.visibility != Some(hir::Public) {
|
||||
return None
|
||||
}
|
||||
}
|
||||
|
||||
clean::StructFieldItem(..) => {
|
||||
if i.visibility != Some(hir::Public) {
|
||||
return Some(clean::Item {
|
||||
|
|
@ -170,6 +164,9 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
return None;
|
||||
}
|
||||
}
|
||||
// handled in the `strip-priv-imports` pass
|
||||
clean::ExternCrateItem(..) | clean::ImportItem(_) => {}
|
||||
|
||||
clean::DefaultImplItem(..) | clean::ImplItem(..) => {}
|
||||
|
||||
// tymethods/macros have no control over privacy
|
||||
|
|
@ -242,6 +239,21 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// This stripper discards all private import statements (`use`, `extern crate`)
|
||||
struct ImportStripper;
|
||||
impl fold::DocFolder for ImportStripper {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
match i.inner {
|
||||
clean::ExternCrateItem(..) |
|
||||
clean::ImportItem(..) if i.visibility != Some(hir::Public) => None,
|
||||
_ => self.fold_item_recur(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_priv_imports(krate: clean::Crate) -> plugins::PluginResult {
|
||||
(ImportStripper.fold_crate(krate), None)
|
||||
}
|
||||
|
||||
pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
|
||||
struct CommentCleaner;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue