-
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
suggest crate::...
for "local" paths in 2018
#54391
Conversation
6abb101
to
317163a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, nice!
The code looks pretty good to me. I think there are some policy questions, e.g. the way that it prefers |
Or, I guess that the current heuristic is:
It feels like it might be reasonable to show more than one, too, though it'd be silly to do so if they are the same thing underneath. |
Yeah, I've ordered these entirely arbitrarily - we can adjust that. I also experimented with having it attempt to correct misspellings but I couldn't quite tweak it so it wasn't over- or under-correcting. I would get it so if I had |
I'm feeling a bit confused now because I know there is also this |
Maybe that code is only invoked if the |
r? @eddyb |
@nikomatsakis If it is at all helpful, these are the rough notes I threw together when initially working out what was happening and where these errors were coming from: Searching for the error message, we find it in rust/src/librustc_resolve/lib.rs Lines 3673 to 3689 in 186fe09
This returns a
rust/src/librustc_resolve/resolve_imports.rs Lines 876 to 880 in 186fe09
rust/src/librustc_resolve/resolve_imports.rs Lines 628 to 631 in 186fe09
Later, rust/src/librustc_resolve/resolve_imports.rs Lines 657 to 659 in 186fe09
rust/src/librustc_resolve/resolve_imports.rs Lines 960 to 973 in 186fe09
This then goes back to rust/src/librustc_resolve/resolve_imports.rs Line 728 in 186fe09
That vector then is passed to rust/src/librustc_resolve/resolve_imports.rs Line 805 in 186fe09
rust/src/librustc_resolve/resolve_imports.rs Line 821 in 186fe09
|
crate::...
for "local" paths in 2018crate::...
for "local" paths in 2018
|
||
for name in &external_crate_names { | ||
// Don't suggest meta as it will error in `resolve_path`. | ||
if name.as_str() == "meta" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding this is wrong - you want to use something like this instead:
rust/src/librustc_resolve/lib.rs
Lines 4403 to 4407 in c222479
if self.session.rust_2018() { | |
let extern_prelude_names = self.extern_prelude.clone(); | |
for &name in extern_prelude_names.iter() { | |
let ident = Ident::with_empty_ctxt(name); | |
match self.crate_loader.maybe_process_path_extern(name, ident.span) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this.
I think this PR might need to check the edition? Or somehow involve the compat lints. |
@eddyb I've added a test demonstrating the 2015 behaviour for the same test case. |
@bors r+ |
📌 Commit 1525e97 has been approved by |
suggest `crate::...` for "local" paths in 2018 Fixes rust-lang#54230. This commit adds suggestions for unresolved imports in the cases where there could be a missing `crate::`, `super::`, `self::` or a missing external crate name before an import. r? @nikomatsakis
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This commit adds suggestions for unresolved imports in the cases where there could be a missing `crate::`, `super::`, `self::` or a missing external crate name before an import.
Previously, `meta` crate was hardcoded as attempting to resolve a path with it would ICE. Now, we attempt to load each extern crate first so that resolving a path involving that crate doesn't error.
Adds a test to demonstrate behaviour of suggestions in the 2015 edition.
This commit ensures that the external crate suggestion is deterministic by using a `BTreeMap` rather than a `FxHashMap`. This is particularly useful as `std` and `core` will often contain the same items and therefore the suggestion would previously suggest either for any given error - in this case, the suggestion will always prefer `std` now.
@bors r=petrochenkov |
📌 Commit 5872d3e has been approved by |
suggest `crate::...` for "local" paths in 2018 Fixes #54230. This commit adds suggestions for unresolved imports in the cases where there could be a missing `crate::`, `super::`, `self::` or a missing external crate name before an import. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Fixes #54230.
This commit adds suggestions for unresolved imports in the cases where
there could be a missing
crate::
,super::
,self::
or a missingexternal crate name before an import.
r? @nikomatsakis