Skip to content

Linting public reexport of private dependencies #143856

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mladedav
Copy link
Contributor

@mladedav mladedav commented Jul 12, 2025

Part of public/private dependencies #44663
Partially addresses #71043

I'm adding a warning for reexports of private dependencies into rustc_resolve. I get that this should not be a warning, but should instead be a lint to be controlled by the feature gate, but I did not figure out how exactly to do that at that point. I tried doing the same thing as is done in rustc_privacy, but the linting system is not ready yet as far as I understand the error I got, so I made a warning for now instead. Some guidance on how to emit lints with dcx would be appreciated.

This also sets the std_detect crate as a public dependency of std because some macros are reexported from there. I did not check closer, but the other option may be to allow the specific reexports instead.

@rustbot
Copy link
Collaborator

rustbot commented Jul 12, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 12, 2025
@compiler-errors
Copy link
Member

r? petrochenkov perhaps

@bors
Copy link
Collaborator

bors commented Jul 13, 2025

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

@petrochenkov
Copy link
Contributor

I'm adding a warning for reexports of private dependencies into rustc_resolve. I get that this should not be a warning, but should instead be a lint to be controlled by the feature gate, but I did not figure out how exactly to do that at that point. I tried doing the same thing as is done in rustc_privacy, but the linting system is not ready yet as far as I understand the error I got, so I made a warning for now instead. Some guidance on how to emit lints with dcx would be appreciated.

See calls to buffer_lint in rustc_resolve, they can be used as examples.

self.tcx.with_stable_hashing_context(|hcx| self.module_children.to_sorted(&hcx, false))
{
for import in module_children {
if !import.vis.is_public() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to move the lint logic to check_hidden_glob_reexports.

That function already has a very similar logic for iterating over bindings.
And also the effective visibility table is already populated there so you can do checks like self.effective_visibilities.is_exported(def_id) instead of just relying on pub and getting false positives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it there.

Should I rename the function to something like check_reexports? I can't think of anything more specific but it already wasn't checking just for hidden globs and now I feel I'm making the naming situation worse.

@petrochenkov petrochenkov 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 Jul 14, 2025
@mladedav mladedav force-pushed the dm/private-reexport branch from 070e53d to d2fc98c Compare July 14, 2025 20:38
@mladedav
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@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 Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

5 participants