Skip to content

Suggest public re-exports when a private module makes an import path inaccessible#154610

Open
jakubadamw wants to merge 4 commits intorust-lang:mainfrom
jakubadamw:issue-13065
Open

Suggest public re-exports when a private module makes an import path inaccessible#154610
jakubadamw wants to merge 4 commits intorust-lang:mainfrom
jakubadamw:issue-13065

Conversation

@jakubadamw
Copy link
Copy Markdown
Contributor

@jakubadamw jakubadamw commented Mar 30, 2026

This is an attempt at solving #13065.

When a use path fails because it passes through a private module (E0603), and a public re-export of the target item exists elsewhere, the compiler will now suggest importing through that re-export instead.

For example, given:

mod outer {
    pub use self::inner::MyStruct;
    mod inner {
        pub struct MyStruct;
    }
}

use outer::inner::MyStruct; // error: module `inner` is private

the compiler will now suggest use outer::MyStruct; - the publicly accessible path - rather than just pointing at the private module definition and leaving the user to figure out the alternative.

When possible, relative paths are suggested, including those using super (currently capped at a maximum of one super path item).

The newly added test is parametrised by editions because of the change in behaviour around crate::-prefixed imports in edition 2018. Perhaps that’s an overkill – I’ll be happy to remove the variations for editions 2021 and 2024.

Closes #13065.

When an import like `use crate::a::b::Item` fails because module `b` is
private, the resolver now looks up public re-export paths for `Item` and
suggests them to the user.
@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 Mar 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 69 candidates
  • Random selection from 13 candidates

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.

Private items with a public reexport could suggest the public path in privacy error message

3 participants