Skip to content

Fix invalid suggestions and misleading notes for imports - #162688

Open
chenyukang wants to merge 3 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-149418-private-import-alias-suggestion-2
Open

chenyukang wants to merge 3 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-149418-private-import-alias-suggestion-2

Conversation

@chenyukang

@chenyukang chenyukang commented Sep 12, 2026

Copy link
Copy Markdown
Member

Fixes #149418

It's better to review by commits.

The first commit is adding test.

The second commit is trying to fix the original issue in #149418.

The last commit fix a seperated accessibility issue by the way.

@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 Sep 12, 2026
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

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

@petrochenkov

Copy link
Copy Markdown
Contributor

@rustbot reroll

@rustbot rustbot assigned mu001999 and unassigned petrochenkov Sep 13, 2026
@rust-bors

rust-bors Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

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

@mu001999 mu001999 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

--> $DIR/private-import-alias-public-parent-issue-149418.rs:30:13
|
LL | pub use self::private::Item;
| ^^^^^^^^^^^^^^^^^^^ you could import this re-export

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems we should keep this label, right? Like what we did at line 43 and 75 in this file.

LL | pub struct Item;
| ^^^^^^^^^^^^^^^^ you could import this directly
| ^^^^^^^^^^^^^^^^
help: import `Alias` through the re-export

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a little confused, could this be import `Item` through the re-export?

@@ -102,8 +102,8 @@ LL | pub const PEAR: &str = "Pear";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ you could import this directly
help: import `fruit` directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, could this be import `PEAR` directly?

Comment on lines +72 to +113

mod crate_visible {
pub(crate) struct Item;

pub mod nested {
use crate::crate_visible::Item as Alias;
}
}

fn check_crate_visible() {
// A crate-visible definition can be recommended from within the same crate.
let _: crate_visible::nested::Alias;
//~^ ERROR struct import `Alias` is private
}

mod inaccessible_import {
use crate::public_reexport::Item;

pub mod nested {
use super::Item as Alias;
}
}

mod accessible_import {
use crate::public_reexport::Item;

mod nested {
use super::Item as Alias;
}

mod use_site {
fn check() {
// The private import in our parent module is accessible here.
let _: super::nested::Alias;
//~^ ERROR struct import `Alias` is private
// `super::Item` resolves here, but not through `inaccessible_import::Item`.
// Do not recommend that inaccessible binding merely because its `Res` matches.
let _: crate::inaccessible_import::nested::Alias;
//~^ ERROR struct import `Alias` is private
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also add this part in the first commit? It would helpful for reviewing. Thanks :)

@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 Sep 17, 2026
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-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 : constant import ... is private gives incrorrect suggestions

4 participants