Uh oh!
There was an error while loading. Please reload this page.
Bug #21221: Show candidates for names not in scope - #31674
Conversation
rust-highfive
commented
Feb 15, 2016
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
This should probably stay debug!(...);
There was a problem hiding this comment.
Oops, sorry, will fix in a moment.
5155347 to
5870906CompareVladUreche
commented
Feb 15, 2016
The previous commit failed to build after the rebase on the latest |
There was a problem hiding this comment.
change to else if !paths.is_empty() to remove the empty if-block above
VladUreche
commented
Feb 16, 2016
@oli-obk Thank you for the suggestions! I will push an update asap. |
bors
commented
Feb 17, 2016
☔ The latest upstream changes (presumably #31685) made this pull request unmergeable. Please resolve the merge conflicts. |
VladUreche
commented
Feb 17, 2016
Thanks Bors, nice helpful robot :) |
nikomatsakis
commented
Feb 18, 2016
cc @jseyfried@petrochenkov, resident resolve experts :) |
There was a problem hiding this comment.
Nit: put these on two separate lines (lining up the .) -- seems a bit long for one line to me
nikomatsakis
commented
Feb 18, 2016
OK, did a read through and left some notes -- this looks pretty good to me, actually. I like the suggestion infrastructure, I wonder if there are other places it could profitably be employed. I left some nits and some larger comments. |
VladUreche
commented
Feb 18, 2016
@jseyfried, can you please have a look at the conditions now? I will address merging the |
VladUreche
commented
Feb 18, 2016
@nikomatsakis, the commit messages should be much shorter now: VladUreche@ddeb147#diff-aeb0880081a991f34aef2ab889e1fb7aL3735 |
There was a problem hiding this comment.
This should be just !in_module_is_extern || name_binding.is_public()
There was a problem hiding this comment.
Oh, since we prune the search by not adding to the worklist. Good point!
There was a problem hiding this comment.
After making the changes, I realized why I did not go with pruning:
session.fileline_help(
span,
&format!("there are {} other candidates that are not \
accessible.", not_accessible_count),
);
When pruning the search, we do not count all inaccessible definitions with the given name.
There was a problem hiding this comment.
Right now we are collecting all crate local items in lookup_results_accessible, so lookup_results_everything has all the paths that lookup_results_accessible has except for inaccessible external items. I don't think we should report inaccessible external items under any circumstances, so there's no need for the two lists.
There was a problem hiding this comment.
If you want two lists, I think lookup_results_accessible should have all accessible items and lookup_results_everything should also have inaccessible items from the current crate. In that case, you'd need that ancestor checking method to distinguish between inaccessible and accessible items in the current crate. I don't think it's worth it to implement this distinction.
VladUreche
commented
Feb 18, 2016
@jseyfried, the last commit merges the two data structures for storing candidates.
Otherwise, once you had a look at the code, I can squash the commits again. |
jseyfried
commented
Feb 18, 2016
I think we should always report all items in the current crate and all accessible items in external crates and we should never report inaccessible items from external crates. |
jseyfried
commented
Feb 18, 2016
Also, feel free to squash whenever |
VladUreche
commented
Feb 18, 2016
Thanks! I removed the inaccessible definitions list and re-enabled the pruning. I'll have the new commit ready in a few minutes. |
e180806 to
2c613a5CompareThere was a problem hiding this comment.
A couple things:
- To
pub usesomething, it has to bepub, so this example would be an error unlesstrait Twaspub. - Since we don't care about accessibility in the current crate, we would report
foo::bar::T, right? name_binding.is_import()is can only be true for bindings in the current crate since our crate metadata does not distinguish between public imports and public items. If this code were in an external crate, we would reportfoo::Tas desired.
There was a problem hiding this comment.
That simplifies things a lot. I was under the impression that you can "reveal" private parts of a crate through pub use statements. If imports are only visible on the current crate, we're perfectly fine ignoring them 👍
Thanks a lot for explaining this!
There was a problem hiding this comment.
To answer the 2nd bullet point, yes, we would report foo::bar::T.
There was a problem hiding this comment.
No problem, I probably should have mentioned this earlier :)pub use statements actually can "reveal" private parts of a crate, for example
mod foo {pubtraitT{}}pubuse foo::T;// FYI, we wouldn't be able to do this if `trait T` were not `pub`Here, T would not be accessible to other traits if we didn't pub use foo::T.
What I mean by not distinguishing between public imports and public items is that when we load this external crate, both bindings for T will be !binding.is_import() -- that is, we "forget" if bindings came from items or from imports. In other words, we wouldn't be able to distinguish the above external crate from
mod foo {pubuseT;}pubtraitT;There was a problem hiding this comment.
Which, if I'm interpreting well, means we should report external_crate::T as a valid suggestion. Let me add this as a test case 👍
VladUreche
commented
Feb 18, 2016
@jseyfried, thanks for the latest round of feedback. I removed |
jseyfried
commented
Feb 19, 2016
Alright, this look good to me -- thanks @VladUreche! @nikomatsakis We decided to report all items from the current crate (ignoring re-exports) and all accessible items from external crates. |
This commit adds functionality that allows the name resolution pass to search for entities (traits/types/enums/structs) by name, in order to show recommendations along with the errors. For now, only E0405 and E0412 have suggestions attached, as per the request in bug rust-lang#21221, but it's likely other errors can also benefit from the ability to generate suggestions.
VladUreche
commented
Feb 19, 2016
The last commit adds a test case which checks the re-exports from outside crates. Just for the record, there are five possible extensions I'm aware of:
|
nikomatsakis
commented
Feb 19, 2016
@bors r+ |
bors
commented
Feb 19, 2016
📌 Commit 88af8fa has been approved by |
nikomatsakis
commented
Feb 19, 2016
@VladUreche thanks for sticking with it :) |
bors
commented
Feb 20, 2016
⌛ Testing commit 88af8fa with merge cfabd17... |
This commit adds functionality that allows the name resolution pass to search for entities (traits/types/enums/structs) by name, in order to show recommendations along with the errors. For now, only E0405 and E0412 have suggestions attached, as per the request in bug #21221, but it's likely other errors can also benefit from the ability to generate suggestions.
This commit adds functionality that allows the name resolution pass
to search for entities (traits/types/enums/structs) by name, in
order to show recommendations along with the errors.
For now, only E0405 and E0412 have suggestions attached, as per the
request in bug #21221, but it's likely other errors can also benefit
from the ability to generate suggestions.