Skip to content

Commit 7d338fe

Browse files
committed
Auto merge of #32055 - mitaa:rdoc-strip-priv-imports, r=alexcrichton
fixes #27104 r? @alexcrichton
2 parents 1f5d524 + 062a719 commit 7d338fe

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ const PASSES: &'static [Pass] = &[
109109
"concatenates all document attributes into one document attribute"),
110110
("strip-private", passes::strip_private,
111111
"strips all private items from a crate which cannot be seen externally"),
112+
("strip-priv-imports", passes::strip_priv_imports,
113+
"strips all private import statements (`use`, `extern crate`) from a crate"),
112114
];
113115

114116
const DEFAULT_PASSES: &'static [&'static str] = &[

passes.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
106106
retained: &mut retained,
107107
access_levels: &access_levels,
108108
};
109-
krate = stripper.fold_crate(krate);
109+
krate = ImportStripper.fold_crate(stripper.fold_crate(krate));
110110
}
111111

112112
// strip all private implementations of traits
@@ -144,12 +144,6 @@ impl<'a> fold::DocFolder for Stripper<'a> {
144144
}
145145
}
146146

147-
clean::ExternCrateItem(..) | clean::ImportItem(_) => {
148-
if i.visibility != Some(hir::Public) {
149-
return None
150-
}
151-
}
152-
153147
clean::StructFieldItem(..) => {
154148
if i.visibility != Some(hir::Public) {
155149
return Some(clean::Item {
@@ -170,6 +164,9 @@ impl<'a> fold::DocFolder for Stripper<'a> {
170164
return None;
171165
}
172166
}
167+
// handled in the `strip-priv-imports` pass
168+
clean::ExternCrateItem(..) | clean::ImportItem(_) => {}
169+
173170
clean::DefaultImplItem(..) | clean::ImplItem(..) => {}
174171

175172
// tymethods/macros have no control over privacy
@@ -239,6 +236,21 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
239236
}
240237
}
241238

239+
// This stripper discards all private import statements (`use`, `extern crate`)
240+
struct ImportStripper;
241+
impl fold::DocFolder for ImportStripper {
242+
fn fold_item(&mut self, i: Item) -> Option<Item> {
243+
match i.inner {
244+
clean::ExternCrateItem(..) |
245+
clean::ImportItem(..) if i.visibility != Some(hir::Public) => None,
246+
_ => self.fold_item_recur(i)
247+
}
248+
}
249+
}
250+
251+
pub fn strip_priv_imports(krate: clean::Crate) -> plugins::PluginResult {
252+
(ImportStripper.fold_crate(krate), None)
253+
}
242254

243255
pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
244256
struct CommentCleaner;

0 commit comments

Comments
 (0)