-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer accessible paths in 'use' suggestions #72623
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@da-x |
@petrochenkov First, Case 1For pub mod foo { // Or `mod foo {`
pub struct Bla;
}
fn main() {
let x = Bar;
} That's why mod extra_layer {
mod foo { // Now `pub mod foo` or `mod foo` matter for `use` potential.
pub struct Bar;
}
}
fn main() {
let x = Bar;
} Case 2Old code skips all imports in the What I did there, is to only skip imports that are at the reference, i.e. I'm adding this as an extra commit. See It would be probably a good idea to add more tests for this, and have them both work with edition 2015 and edition 2018. |
This comment has been minimized.
This comment has been minimized.
@da-x #72789 shows how to pass the "reference module" in a better way and how to compare modules without spans. Once that PR lands, could you split this PR into two PRs, one for the "suggest reexports" heuristic and one for the privacy check heuristic, so their effects on tests could be more clear. |
☔ The latest upstream changes (presumably #72975) made this pull request unmergeable. Please resolve the merge conflicts. |
resolve: Do not suggest imports from the same module in which we are resolving Based on the idea from rust-lang#72623.
#72789 has landed. |
Yes, noticed :) Basing on this, I'm rewriting my original changes - the
newer version is going to have much better test results.
…On Thu, Jun 11, 2020, 20:35 Vadim Petrochenkov ***@***.***> wrote:
#72789 <#72789> has landed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#72623 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACON6PGBSDIEDGJBAXWBADRWEIWLANCNFSM4NK65ZGQ>
.
|
fb920c6
to
a584e44
Compare
@petrochenkov rewrite is finished. |
The move to use |
r=me after squashing the commits. |
This fixes an issue with the following sample: mod foo { mod inaccessible { pub struct X; } pub mod avail { pub struct X; } } fn main() { X; } Instead of suggesting both `use crate::foo::inaccessible::X;` and `use crate::foo::avail::X;`, it should only suggest the latter. It is done by trimming the list of suggestions from inaccessible paths if accessible paths are present. Visibility is checked with `is_accessible_from` now instead of being hard-coded. - Some tests fixes are trivial, and others require a bit more explaining, here are my comments: src/test/ui/issues/issue-35675.stderr: Only needs to make the enum public to have the suggestion make sense. src/test/ui/issues/issue-42944.stderr: Importing the tuple struct won't help because its constructor is not visible, so the attempted constructor does not work. In that case, it's better not to suggest it. The case where the constructor is public is covered in `issue-26545.rs`.
e62f828
to
fea5ab1
Compare
Done. Also, consider for a follow-up PR, maybe to fix the following: mod foo {
mod bar {
pub struct X;
}
pub use self::bar::X;
}
fn main() { X; } This still suggests |
Yeah, not skipping imports would be useful, and it can be done as a separate PR. |
📌 Commit fea5ab1 has been approved by |
…rochenkov Prefer accessible paths in 'use' suggestions This PR addresses issue rust-lang#26454, where `use` suggestions are made for paths that don't work. For example: ```rust mod foo { mod bar { struct X; } } fn main() { X; } // suggests `use foo::bar::X;` ```
…rochenkov Prefer accessible paths in 'use' suggestions This PR addresses issue rust-lang#26454, where `use` suggestions are made for paths that don't work. For example: ```rust mod foo { mod bar { struct X; } } fn main() { X; } // suggests `use foo::bar::X;` ```
…rochenkov Prefer accessible paths in 'use' suggestions This PR addresses issue rust-lang#26454, where `use` suggestions are made for paths that don't work. For example: ```rust mod foo { mod bar { struct X; } } fn main() { X; } // suggests `use foo::bar::X;` ```
Rollup of 6 pull requests Successful merges: - rust-lang#71660 (impl PartialEq<Vec<B>> for &[A], &mut [A]) - rust-lang#72623 (Prefer accessible paths in 'use' suggestions) - rust-lang#73502 (Add E0765) - rust-lang#73580 (deprecate wrapping_offset_from) - rust-lang#73582 (Miri: replace many bug! by span_bug!) - rust-lang#73585 (Do not send a notification for P-high stable regressions) Failed merges: - rust-lang#73581 (Create 0766 error code) r? @ghost
This PR addresses issue #26454, where
use
suggestions are made for paths that don't work. For example: