Skip to content
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

if let for match arm guard? #73764

Closed
tesuji opened this issue Jun 26, 2020 · 4 comments
Closed

if let for match arm guard? #73764

tesuji opened this issue Jun 26, 2020 · 4 comments
Labels
A-patterns Relating to patterns and pattern matching T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Jun 26, 2020

Does it have any design for if let in match arm guard?

match "foobar" {
    s if let Some(tail) = tail.strip_prefix("bar") => dbg!(tail),
    _ => "barbaz",
}

Without if let, I have to indent the if expression a bit:

match "foobar" {
    s => {
        if let Some(tail) = tail.strip_prefix("bar") {
            dbg!(tail)
        } else {
            "barbaz"
        }
    }
}
@tesuji

This comment has been minimized.

@rustbot rustbot added A-patterns Relating to patterns and pattern matching T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 26, 2020
@petrochenkov
Copy link
Contributor

There's an accepted RFC about this - https://github.com/rust-lang/rfcs/blob/master/text/2294-if-let-guard.md

@tesuji
Copy link
Contributor Author

tesuji commented Jun 26, 2020

Thanks. So if let for guard hasn't been implemented.
Should I close this issue for #51114 instead ?

@nagisa
Copy link
Member

nagisa commented Jun 26, 2020

Duplicate of #51114

@nagisa nagisa marked this as a duplicate of #51114 Jun 26, 2020
@nagisa nagisa closed this as completed Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants