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: Render visibilities succinctly #80368

Merged
merged 14 commits into from
Jan 1, 2021
Prev Previous commit
Next Next commit
Handle pub(super)
camelid committed Dec 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 00652e429aaa2250f2561a457e46387bb5b16737
10 changes: 9 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
@@ -1097,12 +1097,20 @@ impl clean::Visibility {
clean::Inherited => Ok(()),

clean::Visibility::Restricted(vis_did) => {
if find_closest_parent_module(tcx, item_did) == Some(vis_did) {
let parent_module = find_closest_parent_module(tcx, item_did);

if parent_module == Some(vis_did) {
// `pub(in foo)` where `foo` is the parent module
// is the same as no visibility modifier
Ok(())
} else if vis_did.index == CRATE_DEF_INDEX {
write!(f, "pub(crate) ")
} else if parent_module
.map(|parent| find_closest_parent_module(tcx, parent))
.flatten()
== Some(vis_did)
{
write!(f, "pub(super) ")
} else {
f.write_str("pub(")?;
let path = tcx.def_path(vis_did);