Skip to content

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

Merged
bors merged 11 commits into
rust-lang:masterfrom
nnethercote:unreachable_pub
Aug 27, 2024
Merged

Add #[warn(unreachable_pub)] to a bunch of compiler crates#126013
bors merged 11 commits into
rust-lang:masterfrom
nnethercote:unreachable_pub

Conversation

@nnethercote

Copy link
Copy Markdown
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

@rustbotrustbot 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
Copy Markdown
Collaborator

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

@KobzolKobzol left a comment

Copy link
Copy Markdown
Member

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.

Comment threadcompiler/rustc_ast_lowering/src/delegation.rs Outdated
@Urgau
Urgau dismissed their stale reviewJune 5, 2024 13:32

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

@compiler-errors

Copy link
Copy Markdown
Contributor

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

@Nadrieril

Copy link
Copy Markdown
Member

r? @Urgau since you seem interested in solving this

@rustbotrustbot assigned Urgau and unassigned NadrierilJun 5, 2024
@nnethercote

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

@Kobzol

Kobzol commented Jun 6, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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

bors commented Jun 7, 2024

Copy link
Copy Markdown
Collaborator

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

@Urgau

Urgau commented Jun 8, 2024

Copy link
Copy Markdown
Member

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

@rustbotrustbot added S-blocked Status: 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
@rustbotrustbot 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: Blocked on something else such as an RFC or other implementation work. labels Jun 29, 2024
@nnethercote

Copy link
Copy Markdown
ContributorAuthor

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.

@nnethercotennethercote changed the title Add #[deny(unreachable_pub)] to a bunch of compiler cratesAdd #[warn(unreachable_pub)] to a bunch of compiler cratesAug 15, 2024
@nnethercote

Copy link
Copy Markdown
ContributorAuthor

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

@Urgau

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Aug 26, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit cc84442 has been approved by Urgau

It is now in the queue for this repository.

@borsbors 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`
This was referenced Aug 26, 2024
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:masterAug 27, 2024
@rustbotrustbot 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
@nnethercotennethercote mentioned this pull request Aug 27, 2024
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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@nnethercote@rustbot@rust-log-analyzer@compiler-errors@Nadrieril@Kobzol@petrochenkov@bors@Urgau@klensy