Skip to content

Shadowing traits via use emits no warnings/errors #7300

Closed
@hoelzro

Description

@hoelzro

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions