Skip to content

overly aggressive ambiguity errors #26187

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

Closed
paulp opened this issue Jun 10, 2015 · 5 comments
Closed

overly aggressive ambiguity errors #26187

paulp opened this issue Jun 10, 2015 · 5 comments

Comments

@paulp
Copy link

paulp commented Jun 10, 2015

% cat a.rs
use std::io::error::*;
use std::thread::*;

fn main() { }

% rustc a.rs
a.rs:2:5: 2:20 error: a type named `Result` has already been imported in this module [E0251]
a.rs:2 use std::thread::*;
           ^~~~~~~~~~~~~~~

Issuing an ambiguity error about a name which is never used does more than create needless busywork and break namespace encapsulation. It means you can never add anything to a module without breaking an unknown and unknowable amount of source code in the wild when you happen to choose the same name as did some other crate.

@paulp
Copy link
Author

paulp commented Jun 10, 2015

Rust is almost pathologically aggressive here. A name which I never use and where all imports leads to the same type (one a straight re-export of the other) is still sufficient cause to fail the compile, e.g.

use std::collections::*;
use std::collections::hash_map::HashMap;

This also illustrates that named imports aren't given priority over wildcard imports.

I initially had high hopes for pub use because in principle it would allow for the construction of a sane convenient namespace. The current error semantics mean that it's unusable for that purpose because it can't be composed with any other imports without creating conflicts - even when the "conflicting" imports are identical to the ones which it is exporting.

@alexcrichton
Copy link
Member

This behavior is currently intended design and the possible breakage is known (and has mitigation strategies).

It's possible to relax these requirements and allow conflicting imports if the conflict isn't actually used, but changes like this would require an RFC (and belong in the rust-lang/rfcs repo). Thanks for the report regardless, though!

@pythonesque
Copy link
Contributor

From the RFC you linked:

However, wildcard imports are now feature gated, and name conflicts in general can be resolved by using the renaming feature of extern crate and use, so in the current non-gated state of the language there is no need for this shadowing behavior.

Since wildcard imports are no longer feature gated, I don't think it's accurate to say that the current behavior is intended.

@aturon
Copy link
Member

aturon commented Jun 17, 2015

Just to clarify, this is not the long-term intended design. Name resolution is currently over-conservative. I think most people want, and expect, precisely the semantics @paulp is laying out here. (In fact, the mitigation strategies @alexcrichton points to are exactly the changes @paulp is asking for.)

However, as @alexcrichton mentions, we don't currently have a fully fleshed-out and approved design here in the form of an RFC, which is our process for undergoing such changes.

cc @nikomatsakis

@glaebhoerl
Copy link
Contributor

cc rust-lang/rfcs#553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants