Skip to content

Wrong matching with enums and overlapping ranges #13867

Closed
@seanmonstar

Description

@seanmonstar
Contributor
#[deriving(Show)]
enum State {
    AtoZ(uint),
    Numeric,
}


fn main() {
    let state = Numeric;
    let b = 97u8; // a
    let r = match (state, b as char) {
        (AtoZ(..), 'a'..'z') => {
            "Named"
        },

        (Numeric, 'x') => {
            "Hex"
        },


        _ => {
            "Other"
        }
    };
    println!("{} {}: {}", state, b as char, r);
}

Outputs Numeric a: Hex. Clearly, a shouldn't match x.

Worth noting: if you change the first range to not include x, such as a..w, it works correctly. Also, removing the field from AtoZ also makes the match work correctly.

Activity

seanmonstar

seanmonstar commented on Apr 30, 2014

@seanmonstar
ContributorAuthor

blocking #13831

lilyball

lilyball commented on May 2, 2014

@lilyball
Contributor

cc me

edwardw

edwardw commented on May 2, 2014

@edwardw
Contributor

This seems to be a regression introduced by #13034.

lilyball

lilyball commented on May 2, 2014

@lilyball
Contributor

This is impacting #13896 as well. I had to add in guards that re-test the range to work around it.

edwardw

edwardw commented on May 2, 2014

@edwardw
Contributor

The defect of #13034 is that it doesn't check multiple refutable patterns, which is exactly what this bug report is about.

added a commit that references this issue on May 5, 2014

5 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @lilyball@seanmonstar@alexcrichton@edwardw

      Issue actions

        Wrong matching with enums and overlapping ranges · Issue #13867 · rust-lang/rust