Skip to content

Commit 9a1f01c

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

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/librustdoc/formats/cache.rs

+15-8
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

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
14
//@ edition:2018
25

36
//@ !has "$.index[*][?(@.name=='inner')]"
@@ -12,3 +15,9 @@ mod inner {
1215
pub use inner::Public;
1316

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

tests/rustdoc-json/reexport/simple_public.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
14
//@ edition:2018
25

36
//@ set inner_id = "$.index[*][?(@.name=='inner')].id"
@@ -14,3 +17,8 @@ pub mod inner {
1417
pub use inner::Public;
1518

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

0 commit comments

Comments
 (0)