-
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
uniform_paths edition 2018 feature emits spurrious ambiguity for the log
crate
#53408
Comments
Well, the ambiguity is there because you're doing If you tried cc @petrochenkov Do we want to support EDIT: even if we don't want to allow this, the error message is abysmal. |
Ahh, interesting. I'd minimized it from the case I actually ran across, which was: use log::{debug, info, log};
fn main() {
debug!("Hello, world!");
} I see now that if I only import
I have essentially zero experience with macros, so am a little unclear if this is even a real issue. I vaguely recall seeing something that would allow the external crate to fix this particular (hygiene?) issue. But... I see why this (my original issue) is happening, and it makes sense now. But it also seems surprising to me that the side-effect of a |
@uberjay Part of why that happens is the use ::log::log;
use log::{debug, info}; it would have the exact same result, as your example (I disambiguated the first one just to assume it somehow works). And in this case, the other two imports are definitely ambiguous, so you really want: use ::log::{debug, info, log}; (if you want to use |
@aturon @joshtriplett @petrochenkov On a slightly separate note, we could allow more things by making the |
Something similar:
But that makes no sense, |
Oookay, It suddenly makes perfect sense, knowing that the order of |
@letheed As I tried to explain above, the import conflicts with itself.
This, for example, has "always" worked: use ::log;
use self::log as renamed_log; The second import refers to the first one (the order doesn't matter, fwiw). If we want to allow |
@eddyb I don't think we want to special-case this, because it's redundant. If you have (Note that such an error message would not trigger on, for instance, |
Example of an error message that makes slightly more sense: use log::{self as log}; error: import from `log` is ambiguous
--> src/main.rs:3:5
|
3 | use log::{self as log};
| ^^^ ----------- could also refer to `self::log`
| |
| could refer to external crate `::log`
|
= help: write `::log` or `self::log` explicitly instead
= note: relative `use` paths enabled by `#![feature(uniform_paths)]` The reason OTOH, |
Mm, yeah. I definitely minimized it too far, taking it all the way to |
This looks purely like a consequence of implementation via import cloning. |
This is how it should work, if I understand the issue correctly. use thing in type;
use thing in value;
use thing in macro; Only the first import should be affected by "uniform path"-related cloning // Desugared into
use self::thing in type;
use ::thing in type;
use self::thing in value;
use self::thing in macro; since the crate universe "module" can't contain neither values nor macros. |
I still don't understand why macros aren't imported by the distinguished name ( The only reason I've seen people cite has to do with the fact that you declare them using |
@internetionals my (possibly mistaken!) understanding was that macro names don't include the |
Note that #53427 should fix the false positive macro ambiguity. |
rustc_resolve: overhaul `#![feature(uniform_paths)]` error reporting. Fixes #53408 by only considering external crates to conflict within their (type/module) namespace, *not* with the value or macro namespaces, and also by adding a special-cased error for redundant `use crate_name;` imports (without actually allowing them). Also, all canaries for a given import are grouped into one diagnostic per namespace, in order to make block-scoped ambiguities clearer. See changed/added tests for more details. r? @petrochenkov cc @aturon @joshtriplett
No your obviously not mistaken. But having something called Now if you do |
I'm fairly sure this is a bug. At the very least It's confusing! Enabling
uniform_paths
, there's a detected ambiguoususe
forlog
. But I can't figure out where the non-crate log is coming from. Furthermore, if I changeuse log;
touse self::log;
, just to see if it'll work, the compiler claims there's nolog
module in the root!I didn't run into any other cases like this (with the projects I've tried it with so far).
cargo new uniform-paths
cargo add log
src/main.rs
:attempting to build:
Changing
log
toself::log
:Playground link: https://play.rust-lang.org/?gist=f749f38540242c143f2e4c41e2f1625c&version=nightly&mode=debug&edition=2018
The text was updated successfully, but these errors were encountered: