Skip to content

Error: identifier is bound more than once in the same pattern when using match and mod #18779

@blastrock

Description

@blastrock

Hi,

Here is a strange bug I came across:

use m::EntityType;

mod m {
    pub enum EntityType {
        Type1,
        Type2,
    }
}

fn do_match(t1: EntityType, t2: EntityType) {
    match (t1, t2) {
        (Type1, Type1) => (),
        (Type2, Type2) => (),
        (Type1, Type2) => (),
        (Type2, Type1) => (),
    }
}

fn main() {}

This code fails to compile with:

<anon>:12:17: 12:22 error: identifier `Type1` is bound more than once in the same pattern
<anon>:12         (Type1, Type1) => (),
                          ^~~~~
<anon>:13:17: 13:22 error: identifier `Type2` is bound more than once in the same pattern
<anon>:13         (Type2, Type2) => (),
                          ^~~~~
error: aborting due to 2 previous errors
playpen: application terminated with error code 101

But it works if we remove the mod block and the use statement, thus putting EntityType in the same namespace.

Tested on master

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions