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

Add #[warn(unreachable_pub)] to a bunch of compiler crates #126013

Merged
merged 11 commits into from
Aug 27, 2024

Conversation

nnethercote
Copy link
Contributor

By default unreachable_pub identifies things that need not be pub and tells you to make them pub(crate). But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add pub(crate) back in everywhere the compiler said it was necessary. (Or occasionally pub(super) when context suggested that was appropriate.) Tedious, but results in more pub removal.

There are plenty more crates to do but this seems like enough for a first PR.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2024

Some changes occurred in coverage instrumentation.

cc @Zalathar

@rust-log-analyzer

This comment has been minimized.

Urgau
Urgau previously approved these changes Jun 5, 2024
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my 2 cents: I prefer the style where you just use pub in the internal modules, and then limit visibility in the parent (for multiple reasons, one of them being that pub(crate) is IMO too verbose). It seems to be more uniform to me, in the sense that you export things from the module, and then decide in the parent what to export further and what not to export, rather than hard-coding the visibility to the whole crate in nested modules.

For example, in rustc_ast_lowering/src/lib.rs, all modules are actually private, and the crate selectively exports (or declares as pub in the root library module) just a few selected items. It doesn't seem to me that adding pub(crate) to many items in the nested modules (which are not reexported from the crate anyway) adds a lot of value.

compiler/rustc_ast_lowering/src/delegation.rs Outdated Show resolved Hide resolved
@Urgau Urgau dismissed their stale review June 5, 2024 13:32

Given the concerns expressed by others, I withdraw my approval.

@compiler-errors
Copy link
Member

Yeah, this is far more reaching than what I was asking for in the original PR (diagnostic structs). I don't have the energy to review this and also don't think we're gaining much -- this really seems like churn.

r? compiler

@rustbot rustbot assigned Nadrieril and unassigned compiler-errors Jun 5, 2024
@Nadrieril
Copy link
Member

r? @Urgau since you seem interested in solving this

@rustbot rustbot assigned Urgau and unassigned Nadrieril Jun 5, 2024
@nnethercote
Copy link
Contributor Author

I personally hate having to look at some outer level (sometimes the immediate struct, sometimes the module, sometimes a use item in an entirely different file) to learn that a seemingly pub thing is not actually pub. But I can see I'm in the minority.

@nnethercote
Copy link
Contributor Author

I also don't understand why this change would be desirable on diagnostic structs but not on other things.

@Kobzol
Copy link
Contributor

Kobzol commented Jun 6, 2024

I personally hate having to look at some outer level (sometimes the immediate struct, sometimes the module, sometimes a use item in an entirely different file) to learn that a seemingly pub thing is not actually pub.

It would be nice if IDEs could show the computed crate visibility on the struct/field. That way we could see both the final visibility, without having to specify pub(crate) everywhere. I created a ticket for RustRover :)

But otherwise, this is just a matter of taste, of course.

@petrochenkov
Copy link
Contributor

I personally hate having to look at some outer level (sometimes the immediate struct, sometimes the module, sometimes a use item in an entirely different file) to learn that a seemingly pub thing is not actually pub. But I can see I'm in the minority.

I also don't like to look elsewhere, but in case of nearly all structs and many impls the outer visibility is in the immediate proximity of the fields/methods, or at worst on the same page. In those cases it's better to avoid the noise and keep just pub.

@bors
Copy link
Contributor

bors commented Jun 7, 2024

☔ The latest upstream changes (presumably #126108) made this pull request unmergeable. Please resolve the merge conflicts.

@Urgau
Copy link
Member

Urgau commented Jun 8, 2024

While I like this change, the concerns expressed by others makes me realize that this change is probably to big to just be approved without further discussion.

The major change proposal page on the forge quotes changing coding conventions as a potential reason for an MCP. @nnethercote if you are interested in pursuing this change further, could you open an MCP for it.

@rustbot author

@rustbot rustbot added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2024
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jun 29, 2024
@nnethercote
Copy link
Contributor Author

I have updated this PR for the new unreachable_pub checking implemented in #126040. The diff has reduced from +946/-917 to +506/-467. Better?

@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote changed the title Add #[deny(unreachable_pub)] to a bunch of compiler crates Add #[warn(unreachable_pub)] to a bunch of compiler crates Aug 15, 2024
@nnethercote
Copy link
Contributor Author

@Urgau: the MCP has passed, so this is ready for final review. Thanks!

@Urgau
Copy link
Member

Urgau commented Aug 26, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 26, 2024

📌 Commit cc84442 has been approved by Urgau

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 26, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 26, 2024
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates

By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal.

There are plenty more crates to do but this seems like enough for a first PR.

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126013 (Add `#[warn(unreachable_pub)]` to a bunch of compiler crates)
 - rust-lang#128157 (deduplicate and clarify rules for converting pointers to references)
 - rust-lang#129032 (Document & implement the transmutation modeled by `BikeshedIntrinsicFrom`)
 - rust-lang#129250 (Do not ICE on non-ADT rcvr type when looking for crate version collision)
 - rust-lang#129340 (Remove Duplicate E0381 Label)
 - rust-lang#129560 ([rustdoc] Generate source link on impl associated types)
 - rust-lang#129622 (Remove a couple of unused feature enables)
 - rust-lang#129625 (Rename `ParenthesizedGenericArgs` to `GenericArgsMode`)
 - rust-lang#129626 (Remove `ParamMode::ExplicitNamed`)

Failed merges:

 - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 110c3df into rust-lang:master Aug 27, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 27, 2024
Rollup merge of rust-lang#126013 - nnethercote:unreachable_pub, r=Urgau

Add `#[warn(unreachable_pub)]` to a bunch of compiler crates

By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal.

There are plenty more crates to do but this seems like enough for a first PR.

r? `@compiler-errors`
@nnethercote nnethercote deleted the unreachable_pub branch August 27, 2024 01:43
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2024
…rgau

More `unreachable_pub`

Add `unreachable_pub` checking to some more compiler crates. A follow-up to rust-lang#126013.

r? `@Urgau`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2024
…rgau

More `unreachable_pub`

Add `unreachable_pub` checking to some more compiler crates. A follow-up to rust-lang#126013.

r? ``@Urgau``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 27, 2024
Rollup merge of rust-lang#129648 - nnethercote:unreachable_pub-2, r=Urgau

More `unreachable_pub`

Add `unreachable_pub` checking to some more compiler crates. A follow-up to rust-lang#126013.

r? ``@Urgau``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants