-
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
rustdoc: add 🔒 to items with restricted visibility #95024
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"Restricted Visibility" seems jargon-y. How about "Private"? https://doc.rust-lang.org/reference/visibility-and-privacy.html says "these two terms are often used interchangeably."
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.
@camelid pointed out that “Private” is a bit ambiguous in this case: #95024 (comment)
The icon/emoji also appears for
pub(...)
items, hence, I think “Restricted Visibility” is more precise. However, I am also fine with “Private” and happy to modify the PR accordingly. :)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.
Thanks for pointing that out.
From the perspective of API design, "private" means "private from a view outside the crate." In other words, it includes everything except what's marked with plain
pub
; it excludespub(crate)
,pub(self)
, etc. Since rustdoc is about APIs, I think it makes sense to use that definition of private. @camelid what do you think?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.
An example may help here. Is the struct
A
in the following snippet private?It cannot be accessed from “outside the crate” because it is in a private module. However, the struct itself is
pub
and will thus not be marked with a 🔒 with the present change. (This also makes sense if we think about designing an API to be used by other modules in the crate which is one of my use cases for this. From the perspective of other modules in the same crate it is indeed public unlike structB
.)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 feel like the
A
struct should be marked as 🔒 since as you said earlier, the 🔒 is about whether it's accessible to code outside the crate. Perhaps that's too technically difficult to implement though?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 agree with this definition for 🔒.
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.
Yes, this seems difficult to implement, at least for me. I do not know how to extract from the compiler whether
A
is somehow publicly accessible or not. Does the compiler have this information at all? I also think it makes sense to think about apub
item in a private module about being public (after all it is explicitly declared public) but with respect to an internal API available to other modules. It is that internal API that is documented. While I agree that Rustdoc is about APIs, I like to challenge that it is primarily about the APIs of crates. Documenting private items and crate internals can be highly valuable, e.g., for bringing contributors up-to-speed or to document the internal architecture and design decision behind it. This is my/our use case for this change.Anyway, what does this discussion entail about the “Restricted Visibility” label? Should that be kept as it currently is or should I change it to “Private”? All items marked that will be marked with 🔒 by the current change are private in the sense that they cannot be accessed from outside the crate.
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.
std::intrinsics::transmute
isn't marked as unstable despitestd::intrinsics
being marked as such. It is re-exported asstd::mem::transmute
. I think the restricted visibility docs should behave the same way. If you look at the docs you can see that the containing module is private. That the item itself isn't is an indication that it may be public through a re-export. Showing it as restricted may cause people to think it isn't accessible in any way at all.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.
Good point, I hadn't thought of that.
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.
There is a query for this, it's named
is_publicly_accessible
or something similar. It's used for unreachable_pub.