Skip to content

Change some pub to pub(crate) in std #107901

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
wants to merge 1 commit into from

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Feb 10, 2023

Most of this was done by enabling warn(unreachable_pub) and using x fix library/std. It's incomplete and doesn't leave the lint enabled as cargo fix doesn't recurse through path dependencies, and only covers items which trigger on my system (x86-64 GNU Linux).

EDIT: Just wanted to note that the motivation for this was #107884, where a very unsound function, only used in tests, was both pub and not marked unsafe

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@clubby789 clubby789 changed the title Change some pub to pub(crate) Change some pub to pub(crate) in std Feb 10, 2023
@clubby789
Copy link
Contributor Author

I have a feeling this is going to take a few iterations to get the windows CI to pass so
@rustbot author

@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-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2023
@clubby789 clubby789 force-pushed the unreachable-pub branch 3 times, most recently from af09e69 to 3c4a623 Compare February 10, 2023 20:23
@clubby789
Copy link
Contributor Author

clubby789 commented Feb 10, 2023

Decided not to touch sys for now because of difficulties with testing it.
@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 Feb 10, 2023
@Mark-Simulacrum Mark-Simulacrum added the I-libs-nominated Nominated for discussion during a libs team meeting. label Feb 12, 2023
@Mark-Simulacrum
Copy link
Member

Nominating for libs. I think this merits a decision on whether we want to do this or not at the team level given how impactful this is across the standard library. (If we do, then incrementally doing so seems ok, and then enabling the lint as we finish with most of the crate. I would probably enable earlier and allow it in e.g. the sys module tree though.

@m-ou-se
Copy link
Member

m-ou-se commented Feb 22, 2023

We discussed this in today's libs meeting. We're generally in favor of doing this (thanks!), but we do want to enable the lint to make sure no new not-actually-pub pub items get added. (If that's too much work to do in one go, please open a tracking issue to track the migration towards pub(crate) in std, to track this and future PRs.)

Also, it seems there are a lot of items that could be pub(super), and while that's not a blocker, it'd be nice if we could limit items to pub(super) where possible, as that helps with readability. (Maybe there should be a lint that can warn when pub(super) would've been enough?)

@clubby789
Copy link
Contributor Author

clubby789 commented Feb 22, 2023

I was able to get most of std automatically pub(crate)'d - the allows are for

  • backtrace - included from a submodule, so I can't fix it here
  • sys/sys_common/os - I can't test/fix all platforms, I'll look at adding an internal deny for the modules I can test here

I'll work on seeing how much of the pub(crate) here can be made pub(super)
@rustbot author

@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-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2023
@clubby789 clubby789 force-pushed the unreachable-pub branch 3 times, most recently from fb72d8d to 1dd36d8 Compare February 22, 2023 23:16
@bors
Copy link
Collaborator

bors commented Feb 27, 2023

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

@Amanieu Amanieu removed the I-libs-nominated Nominated for discussion during a libs team meeting. label Mar 1, 2023
@Dylan-DPC
Copy link
Member

@clubby789 any updates on this?

@clubby789
Copy link
Contributor Author

I'm going to close this for now, as I'm not sure I have the time to make sure this is all done correctly right now 🙁

(Maybe there should be a lint that can warn when pub(super) would've been enough?)

I think this would be a good step to approach first which I might find time to look into 😓

@clubby789 clubby789 closed this Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants