Auto merge of #54201 - eddyb:reflexive-disambiguation, r=petrochenkov

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 https://github.com/rust-lang/rust/issues/53130#issuecomment-420848814:
```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
This commit is contained in:
bors 2018-09-14 19:52:13 +00:00
commit 2ab3eba307
3 changed files with 89 additions and 73 deletions

View file

@ -59,4 +59,12 @@ fn main() {
bar::io::stdout();
bar::std();
bar::std!();
{
// Test that having `io` in a module scope and a non-module
// scope is allowed, when both resolve to the same definition.
use std::io;
use io::stdout;
stdout();
}
}

View file

@ -33,4 +33,12 @@ fn main() {
Foo(());
std_io::stdout();
local_io(());
{
// Test that having `std_io` in a module scope and a non-module
// scope is allowed, when both resolve to the same definition.
use std::io as std_io;
use std_io::stdout;
stdout();
}
}