Skip to content

Private dependencies in public interface lint rework - #160726

Open
mladedav wants to merge 5 commits into
rust-lang:mainfrom
mladedav:dm/public-dependencies-shallow
Open

Private dependencies in public interface lint rework#160726
mladedav wants to merge 5 commits into
rust-lang:mainfrom
mladedav:dm/public-dependencies-shallow

Conversation

@mladedav

@mladedav mladedav commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

Tracking issue: #44663
Closes #119428

This reworks the lint so that it does not fire based on where an item is defined but based on how it is imported. I think this is best illustrated in the following test:

tests/ui/privacy/pub-priv-dep/diamond_deps.rs

The test here is edited for brevity. Note that Shared is the same type and the lint fires only when imported through the private dependency.

// A diamond dependency:
//
//           diamond_reepxort
//                  /\
//        (public) /  \ (PRIVATE)
//                /    \
//   diamond_pub_dep  diamond_priv_dep
//                \    /
//        (public) \  /  (public)
//                  \/
//                shared

#![deny(exported_private_dependencies)]

extern crate diamond_priv_dep;
extern crate diamond_pub_dep;

pub fn leaks_priv() -> diamond_priv_dep::Shared {
    //~^ ERROR type `Shared` from private dependency 'diamond_priv_dep' in public interface
    diamond_priv_dep::Shared
}

// This does NOT produce a lint because the dependency is public
pub fn leaks_pub() -> diamond_pub_dep::Shared {
    diamond_pub_dep::Shared
}

This is my first contribution of this scope and as such, I'm not sure about several things I did:

  • is the new query necessary? The current is_private_dep is not enough since it handles transitively public dependencies as public
  • is it necessary to save this separately into crate metadata? I've modeled it after private_dep so I just did the same things I've seen there.
  • should I use tcx.hir_module_items(mod_id).par_items(..) instead of tcx.hir_visit_all_item_likes_in_crate
    • I think so, but I'd appreciate some guidance here
  • can the old PrivateItemsInPublicInterfacesChecker be trimmed down more so that there are not two passes for this? It still emits hard errors for types in associated types and I'm not sure how to check for this with the visitor.

@epage I'd appreciate if you could check the test changes in the first commit. The state now is how I understand the desired state based on the discussion in #119428 but I'd rather get a final ok on this.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 7, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 7, 2026
@rustbot

rustbot commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@rust-log-analyzer

This comment has been minimized.

@mladedav
mladedav force-pushed the dm/public-dependencies-shallow branch from 45652c2 to 73edae4 Compare August 8, 2026 05:38
@rust-log-analyzer

This comment has been minimized.

@mladedav
mladedav force-pushed the dm/public-dependencies-shallow branch from 73edae4 to 3fd82be Compare August 8, 2026 06:32
@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@JohnTitor

Copy link
Copy Markdown
Member

@rustbot reroll
sorry, I'm not familiar with this

@rustbot rustbot assigned mati865 and unassigned JohnTitor Aug 17, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exported_private_dependencies lint only take effect in innermost dependency

5 participants