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

Enable unreachable_pub lint in core #134286

Merged
merged 4 commits into from
Jan 21, 2025
Merged

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Dec 13, 2024

This PR enables the 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 :

"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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 13, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ibraheemdev
Copy link
Member

This seems reasonable to me, does it need libs signoff?

@Urgau
Copy link
Member Author

Urgau commented Dec 27, 2024

I don't know T-libs customs around enabling new lints. Given that T-compiler as done an MCP I guess it doesn't hurt to at least nominate it.

@rustbot labels -S-waiting-on-review +S-waiting-on-team +I-libs-nominated

@rustbot rustbot added I-libs-nominated Nominated for discussion during a libs team meeting. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 27, 2024
@bors

This comment was marked as resolved.

@bors

This comment was marked as resolved.

@Amanieu
Copy link
Member

Amanieu commented Jan 15, 2025

We discussed this in the libs meeting today, overall several people were in favor of enabling the lint and nobody objected.

@Amanieu Amanieu added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed I-libs-nominated Nominated for discussion during a libs team meeting. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jan 15, 2025
@ibraheemdev
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 16, 2025

📌 Commit 2fa6dbc has been approved by ibraheemdev

It is now in the queue for this repository.

@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2025
@Urgau
Copy link
Member Author

Urgau commented Jan 20, 2025

Fixed the error and rebased. CI is green. Let's try again.

@bors r=ibraheemdev

@bors
Copy link
Contributor

bors commented Jan 20, 2025

📌 Commit 15f345b has been approved by ibraheemdev

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2025
@bors
Copy link
Contributor

bors commented Jan 20, 2025

⌛ Testing commit 15f345b with merge a42d5ec...

@bors
Copy link
Contributor

bors commented Jan 21, 2025

☀️ Test successful - checks-actions
Approved by: ibraheemdev
Pushing a42d5ec to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 21, 2025
@bors bors merged commit a42d5ec into rust-lang:master Jan 21, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 21, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a42d5ec): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary -2.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 764.999s -> 765.476s (0.06%)
Artifact size: 326.01 MiB -> 326.00 MiB (-0.00%)

jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 23, 2025
Enable `unreachable_pub` lint in `test` and `proc_macro` crates

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 `test` and `proc_macro` crates.

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

Continuation of rust-lang#134286

r? libs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 23, 2025
Enable `unreachable_pub` lint in `test` and `proc_macro` crates

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 `test` and `proc_macro` crates.

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

Continuation of rust-lang#134286

r? libs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 23, 2025
Enable `unreachable_pub` lint in `test` and `proc_macro` crates

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 `test` and `proc_macro` crates.

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

Continuation of rust-lang#134286

r? libs
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 24, 2025
Rollup merge of rust-lang#135366 - Urgau:unreach_pub-std-2, r=cuviper

Enable `unreachable_pub` lint in `test` and `proc_macro` crates

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 `test` and `proc_macro` crates.

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

Continuation of rust-lang#134286

r? libs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 28, 2025
Enable `unreachable_pub` lint in `alloc`

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 `alloc` crate.

Most of changes are in the btree implementation and in tests.

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

Continuation of rust-lang#134286 and rust-lang#135366

r? libs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 28, 2025
Enable `unreachable_pub` lint in `alloc`

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 `alloc` crate.

Most of changes are in the btree implementation and in tests.

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

Continuation of rust-lang#134286 and rust-lang#135366

r? libs
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2025
Rollup merge of rust-lang#135367 - Urgau:unreach_pub-std-3, r=Noratrieb

Enable `unreachable_pub` lint in `alloc`

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 `alloc` crate.

Most of changes are in the btree implementation and in tests.

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

Continuation of rust-lang#134286 and rust-lang#135366

r? libs
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 6, 2025
…, r=Noratrieb

Fix `unreachable_pub` lint for hermit target

The build for the hermit target (`#[cfg(target_os = "hermit")]`) fails on master as of [8df89d1](rust-lang@8df89d1) (2025-02-05), due to introducing `#[warn(unreachable_pub)]` at the root in rust-lang#134286 (Enable unreachable_pub lint in core, merged 2025-01-20).

Make the relevant visibility modifiers more specific to resolve the warning.

```
$ ./x build --target x86_64-unknown-hermit
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.34s
Building stage0 library artifacts (x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.15s
Building compiler artifacts (stage0 -> stage1, x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 1.67s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 library artifacts {alloc, core, panic_abort, panic_unwind, proc_macro, std, sysroot, test, unwind} (x86_64-apple-darwin -> x86_64-unknown-hermit)
   Compiling panic_unwind v0.0.0 (library/panic_unwind)
error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:10:9
   |
10 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates
   = note: `-D unreachable-pub` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unreachable_pub)]`

error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:17:9
   |
17 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates

error: could not compile `panic_unwind` (lib) due to 2 previous errors
Build completed unsuccessfully in 0:00:39
```
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
Rollup merge of rust-lang#136595 - thaliaarchi:hermit-unreachable-pub, r=Noratrieb

Fix `unreachable_pub` lint for hermit target

The build for the hermit target (`#[cfg(target_os = "hermit")]`) fails on master as of [8df89d1](rust-lang@8df89d1) (2025-02-05), due to introducing `#[warn(unreachable_pub)]` at the root in rust-lang#134286 (Enable unreachable_pub lint in core, merged 2025-01-20).

Make the relevant visibility modifiers more specific to resolve the warning.

```
$ ./x build --target x86_64-unknown-hermit
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.34s
Building stage0 library artifacts (x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.15s
Building compiler artifacts (stage0 -> stage1, x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 1.67s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 library artifacts {alloc, core, panic_abort, panic_unwind, proc_macro, std, sysroot, test, unwind} (x86_64-apple-darwin -> x86_64-unknown-hermit)
   Compiling panic_unwind v0.0.0 (library/panic_unwind)
error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:10:9
   |
10 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates
   = note: `-D unreachable-pub` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unreachable_pub)]`

error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:17:9
   |
17 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates

error: could not compile `panic_unwind` (lib) due to 2 previous errors
Build completed unsuccessfully in 0:00:39
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants