Skip to content
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

rustc_resolve: don't treat uniform_paths canaries as ambiguities unless they resolve to distinct Def's. #54201

Merged
merged 3 commits into from
Sep 14, 2018

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Sep 13, 2018

In particular, this allows this pattern that @cramertj mentioned in #53130 (comment):

use log::{debug, log};
fn main() {
    use log::{debug, log};
    debug!(...);
}

The canaries for the inner use log::...;, in the macro namespace, see the log macro imported at the module scope, and the (same) log macro, imported in the block scope inside main.

Previously, these two possible (macro namspace) log resolutions would be considered ambiguous (from a forwards-compat standpoint, where we might make imports aware of block scopes).

With this PR, such a case is allowed if and only if all the possible resolutions refer to the same definition (more specifically, because the same log macro is being imported twice).
This condition subsumes previous (weaker) checks like #54005 and the second commit of #54011.

Only the last commit is the main change, the other two are cleanups.

r? @petrochenkov cc @Centril @joshtriplett

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 13, 2018
@Centril
Copy link
Contributor

Centril commented Sep 13, 2018

Per conversation in Discord we should have a test that has something like use log::{debug, log}; with the cross-crate stuff but I hear --extern is in a different PR so let's follow up on that. =P

This LGTM otherwise :)

@petrochenkov
Copy link
Contributor

petrochenkov commented Sep 13, 2018

The canaries for the inner use log::...;, in the macro namespace, see the log macro imported at the module scope, and the (same) log macro, imported in the block scope inside main.

Do you mean one use log as _; conflicts with another use log as _;?
I don't think this should happen - canaries for use prefix::... need only be created in type namespace.
Canaries in other namespaces are only necessary for single segment imports (use log;).

@petrochenkov petrochenkov 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 13, 2018
@eddyb
Copy link
Member Author

eddyb commented Sep 14, 2018

@petrochenkov I agree in principle, although it's a bit more thorny than that, because one of the initial goals was to be independent of the rest of the import, but also handling use foo::{self}; is harder.

@petrochenkov
Copy link
Contributor

Ok, that's an orthogonal issue, regardless of that resolutions with same Def are acceptable.
@bors r+

@bors
Copy link
Contributor

bors commented Sep 14, 2018

📌 Commit 514c6b6 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 14, 2018
@Mark-Simulacrum
Copy link
Member

@bors p=5 edition critical

@bors
Copy link
Contributor

bors commented Sep 14, 2018

⌛ Testing commit 514c6b6 with merge 2ab3eba...

bors added a commit that referenced this pull request Sep 14, 2018
rustc_resolve: don't treat uniform_paths canaries as ambiguities unless they resolve to distinct Def's.

In particular, this allows this pattern that @cramertj mentioned in #53130 (comment):
```rust
use log::{debug, log};
fn main() {
    use log::{debug, log};
    debug!(...);
}
```
The canaries for the inner `use log::...;`, *in the macro namespace*, see the `log` macro imported at the module scope, and the (same) `log` macro, imported in the block scope inside `main`.

Previously, these two possible (macro namspace) `log` resolutions would be considered ambiguous (from a forwards-compat standpoint, where we might make imports aware of block scopes).

With this PR, such a case is allowed *if and only if* all the possible resolutions refer to the same definition (more specifically, because the *same* `log` macro is being imported twice).
This condition subsumes previous (weaker) checks like #54005 and the second commit of #54011.

Only the last commit is the main change, the other two are cleanups.

r? @petrochenkov cc @Centril @joshtriplett
@bors
Copy link
Contributor

bors commented Sep 14, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 2ab3eba to master...

@bors bors merged commit 514c6b6 into rust-lang:master Sep 14, 2018
@eddyb eddyb deleted the reflexive-disambiguation branch September 15, 2018 06:08
// Currently imports can't resolve in non-module scopes,
// we only have canaries in them for future-proofing.
if external_crate.is_none() && results.module_scope.is_none() {
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, this is now a for loop so I need to continue instead!

Pretty sure this caused #54253, will fix in #54116.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants