Skip to content

Commit 69c6ef8

Browse files
committed
rustdoc-json: Include items in stripped modules in Crate::paths.
1 parent e84163b commit 69c6ef8

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/librustdoc/formats/cache.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct CacheBuilder<'a, 'tcx> {
140140
/// This field is used to prevent duplicated impl blocks.
141141
impl_ids: DefIdMap<DefIdSet>,
142142
tcx: TyCtxt<'tcx>,
143+
is_json_output: bool,
143144
}
144145

145146
impl Cache {
@@ -184,8 +185,13 @@ impl Cache {
184185
}
185186

186187
let (krate, mut impl_ids) = {
187-
let mut cache_builder =
188-
CacheBuilder { tcx, cache: &mut cx.cache, impl_ids: Default::default() };
188+
let is_json_output = cx.is_json_output();
189+
let mut cache_builder = CacheBuilder {
190+
tcx,
191+
cache: &mut cx.cache,
192+
impl_ids: Default::default(),
193+
is_json_output,
194+
};
189195
krate = cache_builder.fold_crate(krate);
190196
(krate, cache_builder.impl_ids)
191197
};
@@ -307,12 +313,13 @@ impl DocFolder for CacheBuilder<'_, '_> {
307313
| clean::ProcMacroItem(..)
308314
| clean::VariantItem(..) => {
309315
use rustc_data_structures::fx::IndexEntry as Entry;
310-
if !self.cache.stripped_mod
311-
&& !matches!(
312-
item.stability.map(|stab| stab.level),
313-
Some(StabilityLevel::Stable { allowed_through_unstable_modules: true, .. })
314-
)
315-
{
316+
317+
let skip_because_unstable = matches!(
318+
item.stability.map(|stab| stab.level),
319+
Some(StabilityLevel::Stable { allowed_through_unstable_modules: true, .. })
320+
);
321+
322+
if (!self.cache.stripped_mod && !skip_because_unstable) || self.is_json_output {
316323
// Re-exported items mean that the same id can show up twice
317324
// in the rustdoc ast that we're looking at. We know,
318325
// however, that a re-exported item doesn't show up in the

tests/rustdoc-json/reexport/simple_private.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ mod inner {
1212
pub use inner::Public;
1313

1414
//@ ismany "$.index[*][?(@.name=='simple_private')].inner.module.items[*]" $use_id
15+
16+
// Test for https://github.com/rust-lang/rust/issues/135309
17+
//@ has "$.paths[*][?(@.kind=='module')].path" '["simple_private"]'
18+
//@ !has "$.paths[*].path" '["simple_private", "inner"]'
19+
//@ has "$.paths[*][?(@.kind=='struct')].path" '["simple_private", "inner", "Public"]'
20+
//@ !has "$.paths[*].path" '["simple_private", "Public"]'

tests/rustdoc-json/reexport/simple_public.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ pub mod inner {
1414
pub use inner::Public;
1515

1616
//@ ismany "$.index[*][?(@.name=='simple_public')].inner.module.items[*]" $import_id $inner_id
17+
18+
//@ has "$.paths[*][?(@.kind=='module')].path" '["simple_public"]'
19+
//@ has "$.paths[*][?(@.kind=='module')].path" '["simple_public", "inner"]'
20+
//@ has "$.paths[*][?(@.kind=='struct')].path" '["simple_public", "inner", "Public"]'
21+
//@ !has "$.paths[*].path" '["simple_public", "Public"]'

0 commit comments

Comments
 (0)