Skip to content

Add missing impl blocks for item reexported from private mod in JSON output #103653

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

Merged
merged 2 commits into from
Oct 29, 2022

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Oct 27, 2022

Fixes #102583.

Since we don't inline for the JSON output, the impl blocks from private modules are not present when we generate the output. To go around this limitation, in case the impl block doesn't have #[doc(hidden)] and is implementing a public item, we don't strip it.

cc @fmease @aDotInTheVoid
r? @notriddle

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 27, 2022
Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

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

Looks good, just some small nits around the test

@@ -0,0 +1,24 @@
// Regression test for <https://github.com/rust-lang/rust/issues/102583>.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This should be in src/test/rustdoc-json/reexport.rs

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,24 @@
// Regression test for <https://github.com/rust-lang/rust/issues/102583>.

// @has "$.index[*][?(@.name=='missing_from_rustdoc_json')]"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you also check that S has an impl block, and the impl block has just the expected method

Copy link
Member Author

Choose a reason for hiding this comment

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

So, for whatever reason I can't do:

// @has "$.index[*][?(@.kind=='impl' && @.inner.for.inner.name=='S')]"

but this one works:

// @has "$.index[*][?(@.kind=='impl')].inner.for.inner.name" '"S"'

I wanted to use it to use to first count the number of impl blocks for S and then count the number of items in this impl. But since it's not possible, I'll just leave it as is I guess...

Copy link
Member

Choose a reason for hiding this comment

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

// @has "$.index[*][?(@.kind=='impl' && @.inner.for.inner.name=='S')]"

doesn't work due to freestrings/jsonpath#91

The way I to work around this is to add a doc comment to the impl and select on that, eg

pub struct S;

//// impl S
impl S {
    pub fn is_present() {}
}

// @set impl_S = "$.index[*][?(@.docs=='impl S')].id"
// @set is_present = "$.index[*][?(@.name=='is_present')].id"
// @is "$.index[*][?(@.name=='S')].inner.impls[*]" $impl_S
// @is "$.index[*][?(@.docs=='impl S')].inner.items[*]" $is_present

Copy link
Member Author

Choose a reason for hiding this comment

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

Smart trick! That doesn't allow to see how many impl blocks are implemented on S unfortunately but it's much better than currently. :)

Copy link
Member

Choose a reason for hiding this comment

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

If theirs a second impls on S, then it'll fail because several things match to // @is "$.index[*][?(@.name=='S')].inner.impls[*]" $impl_S, but because this in #[no_core], their are no auto traits.

Similarly, this checks theirs only 1 method in the impl.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, thanks for the explanation! Then I guess it's ready for final review. :)

@GuillaumeGomez GuillaumeGomez force-pushed the missing-impl-private-json branch 2 times, most recently from 2ebd3ea to 9c10ef0 Compare October 28, 2022 10:18
@GuillaumeGomez
Copy link
Member Author

Updated! I'm a bit sad I couldn't extend the test as I wanted but I guess it's enough for now. If you find a way to do it, I'd be very interested!

@GuillaumeGomez
Copy link
Member Author

Updated! Thanks for the suggestion @aDotInTheVoid !

@GuillaumeGomez GuillaumeGomez force-pushed the missing-impl-private-json branch from 9c10ef0 to 2345cd3 Compare October 28, 2022 12:36
@notriddle
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 28, 2022

📌 Commit 2345cd3155e481bd39ad36c91a2d190edca099ed has been approved by notriddle

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 Oct 28, 2022
@bors
Copy link
Collaborator

bors commented Oct 29, 2022

☔ The latest upstream changes (presumably #102233) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 29, 2022
@GuillaumeGomez GuillaumeGomez force-pushed the missing-impl-private-json branch from 2345cd3 to 0ef36b8 Compare October 29, 2022 09:56
@GuillaumeGomez
Copy link
Member Author

@bors r=notriddle rollup

@bors
Copy link
Collaborator

bors commented Oct 29, 2022

📌 Commit 0ef36b8 has been approved by notriddle

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 29, 2022
@bors bors merged commit 05ab16b into rust-lang:master Oct 29, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 29, 2022
@GuillaumeGomez GuillaumeGomez deleted the missing-impl-private-json branch October 30, 2022 10:51
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
Development

Successfully merging this pull request may close these issues.

rustdoc JSON: struct fn missing if re-exported from private mod
5 participants