Skip to content

Commit 3e71f4d

Browse files
committed
Extra context for unreachable_pub lint (fixes #110922)
While experienced Rustaceans no doubt know this sort of thing already, as more of a newbie I had trouble understanding why I was triggering the lint. Hopefully this expanded explanation saves someone else some head-scratching.
1 parent 26e0c57 commit 3e71f4d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/rustc_lint/src/builtin.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1313,10 +1313,14 @@ declare_lint! {
13131313
///
13141314
/// ### Explanation
13151315
///
1316-
/// A bare `pub` visibility may be misleading if the item is not actually
1317-
/// publicly exported from the crate. The `pub(crate)` visibility is
1318-
/// recommended to be used instead, which more clearly expresses the intent
1319-
/// that the item is only visible within its own crate.
1316+
/// The `pub` keyword both expresses an intent for an item to be publicly available, and also
1317+
/// signals to the compiler to make the item publicly accessible. The intent can only be
1318+
/// satisfied, however, if all items which contain this item are *also* publicly accessible.
1319+
/// Thus, this lint serves to identify situations where the intent does not match the reality.
1320+
///
1321+
/// If you wish the item to be accessible elsewhere within the crate, but not outside it, the
1322+
/// `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the
1323+
/// intent that the item is only visible within its own crate.
13201324
///
13211325
/// This lint is "allow" by default because it will trigger for a large
13221326
/// amount existing Rust code, and has some false-positives. Eventually it

0 commit comments

Comments
 (0)