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
6 changes: 3 additions & 3 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
@@ -1099,12 +1099,12 @@ impl clean::Visibility {
clean::Visibility::Restricted(vis_did) => {
let parent_module = find_closest_parent_module(tcx, item_did);

if parent_module == Some(vis_did) {
if vis_did.index == CRATE_DEF_INDEX {
write!(f, "pub(crate) ")
} else 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()
2 changes: 1 addition & 1 deletion src/test/rustdoc/decl_macro_priv.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

#![feature(decl_macro)]

// @has decl_macro_priv/macro.crate_macro.html //pre 'macro crate_macro() {'
// @has decl_macro_priv/macro.crate_macro.html //pre 'pub(crate) macro crate_macro() {'
// @has - //pre '...'
// @has - //pre '}'
pub(crate) macro crate_macro() {}
8 changes: 4 additions & 4 deletions src/test/rustdoc/pub-restricted.rs
Original file line number Diff line number Diff line change
@@ -6,13 +6,13 @@

// @has 'foo/struct.FooPublic.html' '//pre' 'pub struct FooPublic'
pub struct FooPublic;
// @has 'foo/struct.FooJustCrate.html' '//pre' 'struct FooJustCrate'
// @has 'foo/struct.FooJustCrate.html' '//pre' 'pub(crate) struct FooJustCrate'
crate struct FooJustCrate;
// @has 'foo/struct.FooPubCrate.html' '//pre' 'struct FooPubCrate'
// @has 'foo/struct.FooPubCrate.html' '//pre' 'pub(crate) struct FooPubCrate'
pub(crate) struct FooPubCrate;
// @has 'foo/struct.FooSelf.html' '//pre' 'struct FooSelf'
// @has 'foo/struct.FooSelf.html' '//pre' 'pub(crate) struct FooSelf'
pub(self) struct FooSelf;
// @has 'foo/struct.FooInSelf.html' '//pre' 'struct FooInSelf'
// @has 'foo/struct.FooInSelf.html' '//pre' 'pub(crate) struct FooInSelf'
pub(in self) struct FooInSelf;
mod a {
// @has 'foo/a/struct.FooASuper.html' '//pre' 'pub(crate) struct FooASuper'