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

Prefer pub(super) in unreachable_pub lint suggestion #132426

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Oct 31, 2024

This PR updates the unreachable_pub lint suggestion to prefer pub(super) instead of pub(crate) when possible.

cc @petrochenkov
r? @nnethercote

@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 Oct 31, 2024
@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 1, 2024
@Urgau
Copy link
Member Author

Urgau commented Nov 1, 2024

Seems like, one can't reexport a pub(super) items, this a annoying.

mod go {
    pub(super) use fpu_precision::set_precision;

    mod fpu_precision {
        pub(super) fn set_precision<T>() {} // should be `pub(crate)`
    }
}

@Urgau Urgau force-pushed the unreach_pub-super branch from 3fe6228 to 9382e25 Compare November 2, 2024 00:26
@Urgau
Copy link
Member Author

Urgau commented Nov 2, 2024

I've completely reworked the logic to better use the effective visibility.

I've also locally tested the new logic on the core, alloc, panic_unwind and std crates with ./x.py fix and the new suggestions all successfully passed.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 2, 2024
@Urgau Urgau force-pushed the unreach_pub-super branch from 9382e25 to 435695a Compare November 2, 2024 13:26
compiler/rustc_lint/src/builtin.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/builtin.rs Outdated Show resolved Hide resolved
@Urgau Urgau force-pushed the unreach_pub-super branch from 435695a to bd82f93 Compare November 2, 2024 21:06
@nnethercote
Copy link
Contributor

FWIW, I personally find the difference between pub(crate) and pub(super) to be of very little importance in practice, and I almost always use pub(crate). (In contrast, I find the difference between pub(crate|super) and pub is much more important, as is the difference between pub(crate|super) and no visibility.)

Is this change worth the extra complexity?

@petrochenkov
Copy link
Contributor

It's written in a very wordy way, but it's really just one condition when we reset the default pub(crate) recommendation to pub(super), I think it's worth it (after refactoring).

@nnethercote
Copy link
Contributor

r? @petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned nnethercote Nov 4, 2024
@Urgau Urgau force-pushed the unreach_pub-super branch from bd82f93 to 0bc622d Compare November 4, 2024 18:10
@Urgau
Copy link
Member Author

Urgau commented Nov 4, 2024

I've reduced it all to a single (somewhat small) if, not sure if it's better, but it's much less verbose as asked.

@nnethercote
Copy link
Contributor

Have you done a stage 2 build so that the new behaviour is applied to the compiler's own code? Presumably it would require making a lot of additional changes, because warn(unreachable_pub) is used in most of the compiler's own crates.

@Urgau
Copy link
Member Author

Urgau commented Nov 5, 2024

I haven't tested it on the compiler but as said in #132426 (comment) I have tested it for core, alloc, panic_unwind and std; and since then I have also successfully tested it on hyper, html5ever and itertools, no issues automatically applying the suggestions.

@nnethercote
Copy link
Contributor

How many changes were necessary?

@Urgau
Copy link
Member Author

Urgau commented Nov 5, 2024

I don't really understand the question, but what I did is just a cargo fix (or equivalent) for each of them with RUSTFLAGS="-Wunreachable_pub".

I didn't have to fix anything after the cargo fix1. The pub(super) were all as far as I can tell functional.

Footnotes

  1. I did have some issues with rustfix and cargo fix it-self, but those are not related to the lint or it's suggestions.

@nnethercote
Copy link
Contributor

The question is how big is the diff obtained when running cargo fix? I.e. how many pub(crate) occurrences were changed to pub(super)? My guess is there would be a lot.

@nnethercote
Copy link
Contributor

After discussing on Zulip: I was mistakenly thinking that this would suggest pub(super) for pub(crate) occurrences, but it only suggests pub(super) for pub occurrences. So I have no objections to that.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2024

📌 Commit 0bc622d has been approved by petrochenkov

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 Nov 10, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#131781 (Stabilize Arm64EC inline assembly)
 - rust-lang#132426 (Prefer `pub(super)` in `unreachable_pub` lint suggestion)
 - rust-lang#132866 (Break from review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 54cb1f7 into rust-lang:master Nov 10, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2024
Rollup merge of rust-lang#132426 - Urgau:unreach_pub-super, r=petrochenkov

Prefer `pub(super)` in `unreachable_pub` lint suggestion

This PR updates the `unreachable_pub` lint suggestion to prefer `pub(super)` instead of `pub(crate)` when possible.

cc `@petrochenkov`
r? `@nnethercote`
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…enkov

Prefer `pub(super)` in `unreachable_pub` lint suggestion

This PR updates the `unreachable_pub` lint suggestion to prefer `pub(super)` instead of `pub(crate)` when possible.

cc `@petrochenkov`
r? `@nnethercote`
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#131781 (Stabilize Arm64EC inline assembly)
 - rust-lang#132426 (Prefer `pub(super)` in `unreachable_pub` lint suggestion)
 - rust-lang#132866 (Break from review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

6 participants