Skip to content

Shadowing traits via use emits no warnings/errors #7300

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
hoelzro opened this issue Jun 22, 2013 · 1 comment
Closed

Shadowing traits via use emits no warnings/errors #7300

hoelzro opened this issue Jun 22, 2013 · 1 comment

Comments

@hoelzro
Copy link
Contributor

hoelzro commented Jun 22, 2013

The following code compiled with Rust dc4560d:

use Set = std::hashmap::HashSet;

fn main() {
    let set : Set<int> = Set::new();
    set.contains(&3);
    let _ = set;
}

fails to compile with the following message:

/tmp/test2.rs:5:4: 5:21 error: type `std::hashmap::HashSet<int>` does not implement any method in scope named `contains`
/tmp/test2.rs:5     set.contains(&3);
                        ^~~~~~~~~~~~~~~~~

With the help of the wonderful folks on #rust, I was able to determine that the reason is isn't working is that the Set trait is being masked by my alias for std::hashmap::HashSet. I think that the compiler should emit a warning or error to explain what's going on.

@bstrie
Copy link
Contributor

bstrie commented Jul 12, 2013

I think there's a question as to what the proper behavior is here.

Nominating for Well-Defined.

@bstrie bstrie closed this as completed Jul 12, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 1, 2021
Add import_rename lint, this adds a field on the Conf struct

fixes rust-lang#7276

changelog: Add ``[`import_rename`]`` a lint that enforces import renaming defined in the config file.
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

2 participants