Skip to content

Fix relative paths in private import suggestions#157524

Open
qaijuang wants to merge 2 commits into
rust-lang:mainfrom
qaijuang:fix-private-import-relative-path
Open

Fix relative paths in private import suggestions#157524
qaijuang wants to merge 2 commits into
rust-lang:mainfrom
qaijuang:fix-private-import-relative-path

Conversation

@qaijuang

@qaijuang qaijuang commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Resolves #157455.

The private import diagnostic was reusing import.module_path for the "import directly" help. That path is relative to the module where the import was written, so a relative import can be suggested from the wrong place.

For the issue repro, this suggested:

use super::public::hi;

from the crate root. The suggestion should be:

use public::hi;

For relative local imports, this PR rebuilds the help from the resolved module path and only emits it if the item and every module segment are accessible from the failing use site. Additionally, this covers the private-ancestor case from #157455 (comment), where suggesting a direct path would still be invalid. Finally, it maintains an external-alias case as a guardrail to ensure super::s::mem is not treated like a local module path.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2026
@qaijuang qaijuang marked this pull request as ready for review June 6, 2026 09:02
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 6, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 6, 2026
@rustbot

rustbot commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

r? @ShoyuVanilla

rustbot has assigned @ShoyuVanilla.
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 73 candidates
  • Random selection from 20 candidates

@fee1-dead fee1-dead self-assigned this Jun 8, 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.

E0603: relative paths are not being correctly suggested for help: import directly

4 participants