Skip to content

Unclear match behaviour when using multiple patterns and a guard #26012

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
jonhoo opened this issue Jun 4, 2015 · 1 comment
Closed

Unclear match behaviour when using multiple patterns and a guard #26012

jonhoo opened this issue Jun 4, 2015 · 1 comment

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jun 4, 2015

Consider the following code:

fn main() {
    enum E {
        A,
        B,
    }

    let x = E::A;
    let y = true;

    match x {
        E::A | E::B if !y => println!("if applies only to last pattern"),
        _ => println!("if applies to all OR'd patterns"),
    }
}

The behaviour of this code depends on whether the guard applies to only the pattern it succeeds, or to the entire match arm. Running it on nightly behaves as though the guard applies to the entire arm (i.e. the first arm is not matched), but this is not stipulated anywhere in the docs as far as I can tell. If this interpretation of the code is indeed the expected one, then this should be documented.

@steveklabnik
Copy link
Member

It is expected as far as I know.

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