diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index a8eae52fc565e..90f4aaefc9bc1 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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() diff --git a/src/test/rustdoc/decl_macro_priv.rs b/src/test/rustdoc/decl_macro_priv.rs index cb71bca9cf201..4e1279e34d933 100644 --- a/src/test/rustdoc/decl_macro_priv.rs +++ b/src/test/rustdoc/decl_macro_priv.rs @@ -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() {} diff --git a/src/test/rustdoc/pub-restricted.rs b/src/test/rustdoc/pub-restricted.rs index 9ff3cad070d82..f828e642abdca 100644 --- a/src/test/rustdoc/pub-restricted.rs +++ b/src/test/rustdoc/pub-restricted.rs @@ -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'