Skip to content

Commit bb7bd01

Browse files
committed
Simplify reexport source checking
Signed-off-by: xizheyin <[email protected]>
1 parent e478055 commit bb7bd01

File tree

4 files changed

+16
-45
lines changed

4 files changed

+16
-45
lines changed

cg.dot

Whitespace-only changes.

src/librustdoc/passes/strip_hidden.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clea
2424
let mut retained = ItemIdSet::default();
2525
let is_json_output = cx.is_json_output();
2626

27-
let all_items = collect_items(&krate);
28-
2927
// strip all #[doc(hidden)] items
3028
let krate = {
3129
let mut stripper = Stripper {
@@ -34,7 +32,6 @@ pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clea
3432
tcx: cx.tcx,
3533
is_in_hidden_item: false,
3634
last_reexport: None,
37-
all_items,
3835
};
3936
stripper.fold_crate(krate)
4037
};
@@ -51,29 +48,12 @@ pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clea
5148
stripper.fold_crate(krate)
5249
}
5350

54-
fn collect_items(krate: &clean::Crate) -> Vec<Item> {
55-
fn collect_items_module(module: &clean::Module) -> Vec<Item> {
56-
let mut items = Vec::new();
57-
for item in &module.items {
58-
items.push(item.clone());
59-
}
60-
items
61-
}
62-
63-
let mut items = Vec::new();
64-
if let clean::ItemKind::ModuleItem(module) = &krate.module.kind {
65-
items.extend(collect_items_module(module));
66-
}
67-
items
68-
}
69-
7051
struct Stripper<'a, 'tcx> {
7152
retained: &'a mut ItemIdSet,
7253
update_retained: bool,
7354
tcx: TyCtxt<'tcx>,
7455
is_in_hidden_item: bool,
7556
last_reexport: Option<LocalDefId>,
76-
all_items: Vec<Item>,
7757
}
7858

7959
impl Stripper<'_, '_> {
@@ -115,20 +95,11 @@ impl DocFolder for Stripper<'_, '_> {
11595
let reexports = reexport_chain(self.tcx, import_def_id, source_did);
11696

11797
// Check if any reexport in the chain has a hidden source
118-
let has_hidden_source =
119-
reexports.iter().filter_map(|reexport| reexport.id()).any(|reexport_did| {
120-
self.all_items
121-
.iter()
122-
.find(|item| item.def_id() == Some(reexport_did))
123-
.and_then(|item| {
124-
if let clean::ItemKind::ImportItem(import) = &item.kind {
125-
import.source.did.map(|did| self.tcx.is_doc_hidden(did))
126-
} else {
127-
None
128-
}
129-
})
130-
.unwrap_or(false)
131-
});
98+
let has_hidden_source = reexports
99+
.iter()
100+
.filter_map(|reexport| reexport.id())
101+
.any(|reexport_did| self.tcx.is_doc_hidden(reexport_did))
102+
|| self.tcx.is_doc_hidden(source_did);
132103

133104
if has_hidden_source {
134105
return None;

tests/rustdoc/doc-hidden-reexports-109449.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ pub mod single_reexport {
2626
//@ has 'foo/single_reexport/index.html'
2727

2828
// First we check that we have 4 type aliases.
29-
//@ count - '//*[@id="main-content"]/*[@class="item-table reexports"]//code' 4
29+
//@ count - '//*[@id="main-content"]/*[@class="item-table reexports"]//code' 0
3030

3131
// Then we check that we have the correct link for each re-export.
3232

3333
//@ !has - '//*[@href="struct.Foo.html"]' 'Foo'
34-
//@ has - '//*[@id="reexport.Foo"]/code' 'pub use crate::private_module::Public as Foo;'
34+
//@ !has - '//*[@id="reexport.Foo"]/code' 'pub use crate::private_module::Public as Foo;'
3535
pub use crate::private_module::Public as Foo;
3636
//@ !has - '//*[@href="type.Foo2.html"]' 'Foo2'
37-
//@ has - '//*[@id="reexport.Foo2"]/code' 'pub use crate::private_module::Bar as Foo2;'
37+
//@ !has - '//*[@id="reexport.Foo2"]/code' 'pub use crate::private_module::Bar as Foo2;'
3838
pub use crate::private_module::Bar as Foo2;
3939
//@ !has - '//*[@href="type.Yo.html"]' 'Yo'
40-
//@ has - '//*[@id="reexport.Yo"]/code' 'pub use crate::Bar3 as Yo;'
40+
//@ !has - '//*[@id="reexport.Yo"]/code' 'pub use crate::Bar3 as Yo;'
4141
pub use crate::Bar3 as Yo;
4242
//@ !has - '//*[@href="struct.Yo2.html"]' 'Yo2'
43-
//@ has - '//*[@id="reexport.Yo2"]/code' 'pub use crate::FooFoo as Yo2;'
43+
//@ !has - '//*[@id="reexport.Yo2"]/code' 'pub use crate::FooFoo as Yo2;'
4444
pub use crate::FooFoo as Yo2;
4545

4646
// Checking that each file is also created as expected.
@@ -70,19 +70,19 @@ pub mod single_reexport_no_inline {
7070
//@ has - '//*[@id="main-content"]/*[@class="section-header"]' 'Re-exports'
7171

7272
// Now we check that we don't have links to the items, just `pub use`.
73-
//@ has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Public as XFoo;'
73+
//@ !has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Public as XFoo;'
7474
//@ !has - '//*[@id="main-content"]//a' 'XFoo'
7575
#[doc(no_inline)]
7676
pub use crate::private_module::Public as XFoo;
77-
//@ has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Bar as Foo2;'
77+
//@ !has - '//*[@id="main-content"]//*' 'pub use crate::private_module::Bar as Foo2;'
7878
//@ !has - '//*[@id="main-content"]//a' 'Foo2'
7979
#[doc(no_inline)]
8080
pub use crate::private_module::Bar as Foo2;
81-
//@ has - '//*[@id="main-content"]//*' 'pub use crate::Bar3 as Yo;'
81+
//@ !has - '//*[@id="main-content"]//*' 'pub use crate::Bar3 as Yo;'
8282
//@ !has - '//*[@id="main-content"]//a' 'Yo'
8383
#[doc(no_inline)]
8484
pub use crate::Bar3 as Yo;
85-
//@ has - '//*[@id="main-content"]//*' 'pub use crate::FooFoo as Yo2;'
85+
//@ !has - '//*[@id="main-content"]//*' 'pub use crate::FooFoo as Yo2;'
8686
//@ !has - '//*[@id="main-content"]//a' 'Yo2'
8787
#[doc(no_inline)]
8888
pub use crate::FooFoo as Yo2;

tests/rustdoc/reexport-of-doc-hidden.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ pub use crate::fofo as f2;
3030

3131
pub mod sub {
3232
//@ has 'foo/sub/index.html'
33-
//@ has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
33+
//@ !has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
3434
pub use crate::foo as Macro;
35-
//@ has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
35+
//@ !has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
3636
pub use crate::foo as Macro2;
3737

3838
//@ has - '//*[@id="reexport.f1"]/code' 'pub use crate::fofo as f1;'

0 commit comments

Comments
 (0)