-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix dangling ID when pub use
ing item which is Doc(hidden) or inherits it in rustdoc JSON output
#117810
Fix dangling ID when pub use
ing item which is Doc(hidden) or inherits it in rustdoc JSON output
#117810
Conversation
rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi Some changes occurred in src/librustdoc/clean/types.rs cc @camelid |
This comment has been minimized.
This comment has been minimized.
e1fb934
to
7885239
Compare
I rebased and updated the failing test (it was testing something changed in this PR). |
I have a serious concern here, and a request to reconsider the interpretation of how Let's look at this example from the doc comment: #[doc(hidden)]
pub mod foo {
pub struct Bar;
}
pub use foo::Bar; To me, this seems like a public re-export of an intended-to-be-public item. In other words, when I see this code, I expect its If It also seems to risk opening a terrible can of worms with further edge cases: mod defn {
pub struct Example;
}
#[doc(hidden)]
pub mod hide {
pub use crate::Example as Example;
}
// Here, `Example` is public API.
pub use defn::Example;
// Replace it with the below code and `Example` is no longer public API.
// Worse, we can't distinguish between these two cases via rustdoc JSON,
// so this interpretation would permanently break cargo-semver-checks.
// pub use hide::Example; For these reasons, I think a better interpretation of whether an item is |
I followed the same existing logic as for public item in private module: mod x {
pub struct Y {}
}
/// a
pub use x::Y as Z; So I agree with you, but then this would be a change to be done in another PR as it would change how we handle things completely. |
Thanks! Just to double-check since it's important for cargo-semver-checks:
Am I correct in understanding that you feel the "reachability" interpretation I proposed should be how I'm asking because I wanted to release a new cargo-semver-checks version next week with the ability to ignore |
I plan to at least open a discussion about how reexported items from private/hidden modules should appear in the JSON output. I'm not too happy with the current situation as it differs between the HTML and JSON outputs. The HTML output inline the items, showing all their information, whereas the JSON output just shows a reexport and we can't get the information of the reexported item. So I suggest this: please open an issue on this repository and start a discussion on zulip so we can all agree exactly on what we want and once we reach a consensus (between rustdoc team members and cargo-semver-checks), we'll implement this change. Does it sound good to you? And again: this PR is really about fixing a current bug while not changing the current situation. So it'd be nice to have it merged ahead of time so we can at least have tests to update when we change JSON output. |
Absolutely. I'll open a separate issue and Zulip discussion 👍 Thanks again! |
src/librustdoc/json/conversions.rs
Outdated
let (name, glob, id) = match import.kind { | ||
ImportKind::Simple(s) => { | ||
let is_from_doc_hidden = | ||
import.imported_item_is_doc_hidden(tcx) || import.inherits_doc_hidden(tcx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: The definition of inherits_doc_hidden
already calls imported_item_is_doc_hidden
. That should be de-duplicated, either here or there.
@@ -6,8 +6,9 @@ mod repeat_n { | |||
pub struct RepeatN {} | |||
} | |||
|
|||
/// not here | |||
/// is here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right behavior. If the underlying item isn't part of the public API than I don't think the import of it should be either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import is publicly accessible so I don't see why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Ideologically:
RepeatN
has asked to not be part of the public API. We don't show it in the HTML docs. - Practicly: Theirs very little use to consumers telling them "You import something here, but you don't get to know what it it". If it's a part of the API, we should tell them the full story. If it isn't then we shouldn't acknowledge the import at all. What purpose does this weird in-between serve? (If theirs a compelling use case for just knowing this, that'd easily change my mind)
// @has "$.index[*].inner[?(@.import.name=='UsedHidden')].import.id" "null" | ||
pub use submodule::Hidden as UsedHidden; | ||
// @has "$.index[*].inner[?(@.import.name=='Z')].import.source" '"x::Y"' | ||
// @has "$.index[*].inner[?(@.import.name=='Z')].import.id" 'null' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/pub.20re-export.20of.20item.20from.20.60doc.28hidden.29.60.20module/near/401627083, this import should be a part of the output, and so the ID should be present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the same logic as for reexport of item inside private module. We discussed that after this PR, we want to inline such items and I think in the meantime, this is the right course of action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the same logic as for reexport of item inside private module.
When reexporting an item defined in a private module, the import will have the ID of the underlying item. We should do the same thing here.
We discussed that after this PR, we want to inline such items
Please no. Inlining was a massive source of bugs for rustdoc-json, and removing it was a great improvement. I'm strongly opposed to bringing it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having an ID pointing to an item that is not available means that the current bug fixed by this PR will remain.
…rits it in rustdoc JSON output
…ke new changes into account
7885239
to
2e1fcd6
Compare
☔ The latest upstream changes (presumably #127968) made this pull request unmergeable. Please resolve the merge conflicts. |
I think this PR is not the right way to solve this issue so closing it. |
Fixes #117718.
I changed a bit where we actually filter out some reexports to be done directly in the JSON conversion. When the reexport is public but the reexported item is doc hidden, it generates the reexport but with a
null
ID.r? @aDotInTheVoid