Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustdoc-Json: Don't remove impls for items imported from private modules #100325

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ impl<'a> DocFolder for Stripper<'a> {
}

// handled in the `strip-priv-imports` pass
clean::ExternCrateItem { .. } | clean::ImportItem(..) => {}
clean::ExternCrateItem { .. } => {}
clean::ImportItem(ref imp) => {
// Because json doesn't inline imports from private modules, we need to mark
// the imported item as retained so it's impls won't be stripped.i
//
// FIXME: Is it necessary to check for json output here: See
// https://github.com/rust-lang/rust/pull/100325#discussion_r941495215
if let Some(did) = imp.source.did && self.is_json_output {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could do that. :o

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on stable yet, but let_chains are dope!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

self.retained.insert(did.into());
}
}

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

Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc-json/impls/import_from_private.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://github.com/rust-lang/rust/issues/100252

#![feature(no_core)]
#![no_core]

mod bar {
// @set baz = import_from_private.json "$.index[*][?(@.kind=='struct')].id"
pub struct Baz;
// @set impl = - "$.index[*][?(@.kind=='impl')].id"
impl Baz {
// @set doit = - "$.index[*][?(@.kind=='method')].id"
pub fn doit() {}
}
}

// @set import = - "$.index[*][?(@.kind=='import')].id"
pub use bar::Baz;

// FIXME(adotinthevoid): Use hasexact once #99474 lands

// @has - "$.index[*][?(@.kind=='module')].inner.items[*]" $import
// @is - "$.index[*][?(@.kind=='import')].inner.id" $baz
// @has - "$.index[*][?(@.kind=='struct')].inner.impls[*]" $impl
// @has - "$.index[*][?(@.kind=='impl')].inner.items[*]" $doit