Skip to content

Commit 13ff45d

Browse files
authored
Rollup merge of rust-lang#100325 - aDotInTheVoid:rdj-import-impl, r=GuillaumeGomez
Rustdoc-Json: Don't remove impls for items imported from private modules After rust-lang#99287, items in private modules may still be in the json output, if a public import accesses them. To reflect this, items that are imported need to be marked as retained in the `Stripper` pass, so their impls arn't removed by `ImplStripper`. [More context on zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Populating.20cache.2Eimpls), thanks to @ jyn514 for helping debug this. ``@rustbot`` modify labels: +A-rustdoc-json +T-rustdoc r? ``@GuillaumeGomez`` Fixes rust-lang#100252 Fixes rust-lang#100242
2 parents 710bd23 + 44b489f commit 13ff45d

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
@@ -88,7 +88,17 @@ impl<'a> DocFolder for Stripper<'a> {
8888
}
8989

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

93103
clean::ImplItem(..) => {}
94104

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)