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 output format, crate.paths does not contain all items #104651

Closed
makspll opened this issue Nov 20, 2022 · 12 comments
Closed

rustdoc --json output format, crate.paths does not contain all items #104651

makspll opened this issue Nov 20, 2022 · 12 comments
Labels
A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@makspll
Copy link

makspll commented Nov 20, 2022

#76578

Code

Running
$ rustup run nightly-2022-11-20 cargo rustdoc -p [email protected] -- -Zunstable-options --output-format json
generates a json file whose paths mapping does not contain many of the internal structures such us:
AssetPathId, SourcePathId, HandleId, LabelId etc.

Not sure if this is intended, but without this mapping there is no way as far as I am aware to retrieve the original import paths to these things.

Version it worked on

nightly-2022-08-01

Version with regression

nightly-2022-11-20

@makspll makspll added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Nov 20, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 20, 2022
@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend labels Nov 22, 2022
@GuillaumeGomez
Copy link
Member

Do you have a minimized example of the regression by any chance?

@Enselic
Copy link
Member

Enselic commented Nov 22, 2022

Not sure if this is intended, but without this mapping there is no way as far as I am aware to retrieve the original import paths to these things.

Due to re-exports, a single item can have many paths. And the path to the "real" item may be inaccessible behind a private mod. To learn about all the paths to an item, you must traverse the items from the root. You must also take into account renames (pub use foo as bar), as well as recursive re-exports.

If you want to look at (one way) of doing that you can look at https://github.com/Enselic/cargo-public-api/blob/main/public-api/src/item_processor.rs

The paths structure in the rustdoc JSON is something that will be removed long term. Because it is not really useful. It contains internal paths, and only one path. Long term, all items shall be part of the index. And the items you mention are already part of the index I think? You can check with cargo public-api:

$ cargo install cargo-public-api
$ rustup install nightly
$ git clone https://github.com/bevyengine/bevy.git ; cd bevy
$ cargo public-api -p bevy_asset  | grep AssetPathId
[...]
pub struct bevy_asset::AssetPathId(_, _)
[...]

cargo public-api parses the rustdoc JSON, so if cargo public-api finds an item, it is part of rustdoc JSON.

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 23, 2022
@makspll
Copy link
Author

makspll commented Nov 26, 2022

Hmm, thanks everyone, it seems that there is a way then to retrieve import paths which I am happy with. Closing and will re-open if there are any issues with this.

@makspll makspll closed this as completed Nov 26, 2022
@GuillaumeGomez
Copy link
Member

Maybe we could provide some methods in the rustdonc-json crate to make it easier for our users to get this information?

@makspll
Copy link
Author

makspll commented Nov 26, 2022

That would be very useful indeed, for context I use these to import structures for which I am generating wrappers

@GuillaumeGomez
Copy link
Member

Then please open another issue (linking to this one) with a short example of your problem so we can provide you a function to make it easier. ;)

@Enselic
Copy link
Member

Enselic commented Nov 27, 2022

@GuillaumeGomez I think you meant to say "the rustdoc-types crate" rather than "the rustdoc-json crate", right?

@makspll The "source" for rustdoc-types is here: https://github.com/rust-lang/rust/tree/master/src/rustdoc-json-types.

@GuillaumeGomez
Copy link
Member

Yes absolutely. Sorry, confused the names.

@Boscop

This comment has been minimized.

@makspll

This comment has been minimized.

@Boscop

This comment has been minimized.

@aDotInTheVoid

This comment has been minimized.

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 C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants