Skip to content

Enable deny(unreachable_pub) on rustc_* crates #773

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

Closed
3 tasks done
nnethercote opened this issue Aug 15, 2024 · 3 comments
Closed
3 tasks done

Enable deny(unreachable_pub) on rustc_* crates #773

nnethercote opened this issue Aug 15, 2024 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@nnethercote
Copy link

nnethercote commented Aug 15, 2024

Proposal

"Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

I have downgraded/removed unecessarily permissive visibilities for many things in many PRs, because I think it genuinely helps with readability. Having automated assistance to catch some cases would be very helpful, and that's what deny(unreachable_pub) provides.

The comment describe the unreachable_pub is quite informative:

    /// The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that
    /// means neither directly accessible, nor reexported, nor leaked through things like return
    /// types.
    ///
    /// ### Example
    ///
    /// ```rust,compile_fail
    /// #![deny(unreachable_pub)]
    /// mod foo {
    ///     pub mod bar {
    ///
    ///     }
    /// }
    /// ```
    ///
    /// {{produces}}
    ///
    /// ### Explanation
    ///
    /// The `pub` keyword both expresses an intent for an item to be publicly available, and also
    /// signals to the compiler to make the item publicly accessible. The intent can only be
    /// satisfied, however, if all items which contain this item are *also* publicly accessible.
    /// Thus, this lint serves to identify situations where the intent does not match the reality.
    ///
    /// If you wish the item to be accessible elsewhere within the crate, but not outside it, the
    /// `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the
    /// intent that the item is only visible within its own crate.         
    ///                                                                    
    /// This lint is "allow" by default because it will trigger for a large
    /// amount existing Rust code, and has some false-positives. Eventually it
    /// is desired for this to become warn-by-default.

rust-lang/rust#126013 is a draft PR that adds this lint to a subset of the rustc_* crates, which gives a good idea of the effect. Lots of pubs get downgraded to pub(crate) (or pub(super)), and some pub/pub(crate)/pub(super)s are removed entirely.

Mentors or Reviewers

None.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@nnethercote nnethercote added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Aug 15, 2024
@rustbot
Copy link
Collaborator

rustbot commented Aug 15, 2024

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Aug 15, 2024
@nnethercote nnethercote changed the title (My major change proposal) Enable deny(unreachable_pub) on rustc_* crates Aug 15, 2024
@Noratrieb
Copy link
Member

@rustbot second

as mentioned in the zulip stream, it should be warn() instead of deny() to respect the preferences but this seems like a good change

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Aug 15, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Aug 15, 2024
@apiraino
Copy link
Contributor

@rustbot label -final-comment-period +major-change-accepted

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Aug 26, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Aug 29, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 12, 2025
…ouxu

run_make_support: add `#![warn(unreachable_pub)]`

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `run_make_support` crate.

Related to rust-lang/compiler-team#773

r? `@jieyouxu`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 12, 2025
…ouxu

run_make_support: add `#![warn(unreachable_pub)]`

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `run_make_support` crate.

Related to rust-lang/compiler-team#773

r? ``@jieyouxu``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 13, 2025
Rollup merge of rust-lang#135411 - Urgau:unreach_pub-run-make, r=jieyouxu

run_make_support: add `#![warn(unreachable_pub)]`

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `run_make_support` crate.

Related to rust-lang/compiler-team#773

r? ``@jieyouxu``
jhpratt added a commit to jhpratt/rust that referenced this issue Jan 16, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 20, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 20, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 22, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
github-merge-queue bot pushed a commit to rust-lang/rust-analyzer that referenced this issue Feb 10, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](rust-lang/compiler-team#773 (comment)) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants