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

Conversation

aDotInTheVoid
Copy link
Member

After #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, thanks to @ jyn514 for helping debug this.

@rustbot modify labels: +A-rustdoc-json +T-rustdoc

r? @GuillaumeGomez

Fixes #100252
Fixes #100242

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 9, 2022
@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Aug 9, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2022
Comment on lines 89 to 95
// 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.
if let Some(did) = imp.source.did {
self.retained.insert(did.into());
Copy link
Member

Choose a reason for hiding this comment

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

does this need to special-case the JSON backend? are we sure this doesn't break anything for the HTML backend?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, as HTML shouldn't have imports to items that arn't retained at this point, due to the strip-priv-imports pass. It also passes all rustdoc html/ui/gui/js tests, but I'm not sure how comprehensive these are.

Copy link
Member

Choose a reason for hiding this comment

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

It's mostly testing that something exists. It's hard to confirm in prevision for something that doesn't and shouldn't exist.

Copy link
Member

Choose a reason for hiding this comment

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

I'd feel more at ease if you added a check for the JSON format. You already have this information in self.is_json_output.

// 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 nessessary to check for json output here: See
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking:

Suggested change
// FIXME: Is it nessessary to check for json output here: See
// FIXME: Is it necessary to check for json output here: See

Fixes a bug where impl of items that were imported from a private module
would be striped

Fixes rust-lang#100252
Fixes rust-lang#100242
//
// FIXME: Is it nessessary 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!

@GuillaumeGomez
Copy link
Member

Looks good to me, thanks! I'll r+ once CI pass.

@GuillaumeGomez
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 15, 2022

📌 Commit 44b489f has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2022
…uillaumeGomez

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
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2022
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#100031 (improve "try ignoring the field" diagnostic)
 - rust-lang#100325 (Rustdoc-Json: Don't remove impls for items imported from private modules)
 - rust-lang#100377 (Replace - with _ in fluent slugs to improve developer workflows)
 - rust-lang#100458 (Adjust span of fn argument declaration)
 - rust-lang#100514 (Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls)
 - rust-lang#100528 (Support 1st group of RISC-V Bitmanip backend target features)
 - rust-lang#100559 (Parser simplifications)
 - rust-lang#100568 (Fix STD build for ESP-IDF)
 - rust-lang#100582 ([rustdoc] Fix handling of stripped enum variant in JSON output format)
 - rust-lang#100586 (Reland changes replacing num_cpus with available_parallelism )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 13ff45d into rust-lang:master Aug 15, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
6 participants