Skip to content

Document that match guards are "distributed" across mutliple patterns #364

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
HMPerson1 opened this issue Jun 24, 2018 · 0 comments
Closed

Comments

@HMPerson1
Copy link

Example function (playground):

fn or(b1: bool, b2: bool) -> bool {
    match (b1, b2) {
        (b, _) | (_, b) if b => true,
        _ => false,
    }
}

When we call or(false, true), it matches the (b, _) pattern, then runs the guard which fails, then matches the (_, b) pattern in the same arm and runs the guard again which succeeds, and then finally returns true.

With the current documentation (book, refererence), it's not clear that after matching (b, _) and failing the guard, it will try to match the (_, b) pattern in the same arm instead of failing the whole arm proceeding to the next arm (_ => false).

See also rust-lang/rust#26998, rust-lang/rust#26012.

(moved from rust-lang/rust#51745)

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

1 participant