Skip to content

Commit b959c75

Browse files
committed
Prefer pub(crate) over no modifier
1 parent 00652e4 commit b959c75

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/librustdoc/html/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,12 @@ impl clean::Visibility {
10991099
clean::Visibility::Restricted(vis_did) => {
11001100
let parent_module = find_closest_parent_module(tcx, item_did);
11011101

1102-
if parent_module == Some(vis_did) {
1102+
if vis_did.index == CRATE_DEF_INDEX {
1103+
write!(f, "pub(crate) ")
1104+
} else if parent_module == Some(vis_did) {
11031105
// `pub(in foo)` where `foo` is the parent module
11041106
// is the same as no visibility modifier
11051107
Ok(())
1106-
} else if vis_did.index == CRATE_DEF_INDEX {
1107-
write!(f, "pub(crate) ")
11081108
} else if parent_module
11091109
.map(|parent| find_closest_parent_module(tcx, parent))
11101110
.flatten()

src/test/rustdoc/decl_macro_priv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(decl_macro)]
44

5-
// @has decl_macro_priv/macro.crate_macro.html //pre 'macro crate_macro() {'
5+
// @has decl_macro_priv/macro.crate_macro.html //pre 'pub(crate) macro crate_macro() {'
66
// @has - //pre '...'
77
// @has - //pre '}'
88
pub(crate) macro crate_macro() {}

src/test/rustdoc/pub-restricted.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
// @has 'foo/struct.FooPublic.html' '//pre' 'pub struct FooPublic'
88
pub struct FooPublic;
9-
// @has 'foo/struct.FooJustCrate.html' '//pre' 'struct FooJustCrate'
9+
// @has 'foo/struct.FooJustCrate.html' '//pre' 'pub(crate) struct FooJustCrate'
1010
crate struct FooJustCrate;
11-
// @has 'foo/struct.FooPubCrate.html' '//pre' 'struct FooPubCrate'
11+
// @has 'foo/struct.FooPubCrate.html' '//pre' 'pub(crate) struct FooPubCrate'
1212
pub(crate) struct FooPubCrate;
13-
// @has 'foo/struct.FooSelf.html' '//pre' 'struct FooSelf'
13+
// @has 'foo/struct.FooSelf.html' '//pre' 'pub(crate) struct FooSelf'
1414
pub(self) struct FooSelf;
15-
// @has 'foo/struct.FooInSelf.html' '//pre' 'struct FooInSelf'
15+
// @has 'foo/struct.FooInSelf.html' '//pre' 'pub(crate) struct FooInSelf'
1616
pub(in self) struct FooInSelf;
1717
mod a {
1818
// @has 'foo/a/struct.FooASuper.html' '//pre' 'pub(crate) struct FooASuper'

0 commit comments

Comments
 (0)