Fix invalid suggestions and misleading notes for imports - #162688
chenyukang wants to merge 3 commits into
Conversation
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rustbot reroll |
|
☔ The latest upstream changes (presumably #162859) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
| --> $DIR/private-import-alias-public-parent-issue-149418.rs:30:13 | ||
| | | ||
| LL | pub use self::private::Item; | ||
| | ^^^^^^^^^^^^^^^^^^^ you could import this re-export |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Also, could this be import `PEAR` directly?
|
|
||
| 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 | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Could you also add this part in the first commit? It would helpful for reviewing. Thanks :)
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.