Skip to content

Commit 44b489f

Browse files
committed
rustdoc: Mark imported items as retained
Fixes a bug where impl of items that were imported from a private module would be striped Fixes #100252 Fixes #100242
1 parent cc4dd6f commit 44b489f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/librustdoc/passes/stripper.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ impl<'a> DocFolder for Stripper<'a> {
8484
}
8585

8686
// handled in the `strip-priv-imports` pass
87-
clean::ExternCrateItem { .. } | clean::ImportItem(..) => {}
87+
clean::ExternCrateItem { .. } => {}
88+
clean::ImportItem(ref imp) => {
89+
// Because json doesn't inline imports from private modules, we need to mark
90+
// the imported item as retained so it's impls won't be stripped.i
91+
//
92+
// FIXME: Is it necessary to check for json output here: See
93+
// https://github.com/rust-lang/rust/pull/100325#discussion_r941495215
94+
if let Some(did) = imp.source.did && self.is_json_output {
95+
self.retained.insert(did.into());
96+
}
97+
}
8898

8999
clean::ImplItem(..) => {}
90100

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://github.com/rust-lang/rust/issues/100252
2+
3+
#![feature(no_core)]
4+
#![no_core]
5+
6+
mod bar {
7+
// @set baz = import_from_private.json "$.index[*][?(@.kind=='struct')].id"
8+
pub struct Baz;
9+
// @set impl = - "$.index[*][?(@.kind=='impl')].id"
10+
impl Baz {
11+
// @set doit = - "$.index[*][?(@.kind=='method')].id"
12+
pub fn doit() {}
13+
}
14+
}
15+
16+
// @set import = - "$.index[*][?(@.kind=='import')].id"
17+
pub use bar::Baz;
18+
19+
// FIXME(adotinthevoid): Use hasexact once #99474 lands
20+
21+
// @has - "$.index[*][?(@.kind=='module')].inner.items[*]" $import
22+
// @is - "$.index[*][?(@.kind=='import')].inner.id" $baz
23+
// @has - "$.index[*][?(@.kind=='struct')].inner.impls[*]" $impl
24+
// @has - "$.index[*][?(@.kind=='impl')].inner.items[*]" $doit

0 commit comments

Comments
 (0)