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

Pattern matching with guards does not allow multiple matches. #551

Closed
viesturz opened this issue Jan 4, 2015 · 3 comments
Closed

Pattern matching with guards does not allow multiple matches. #551

viesturz opened this issue Jan 4, 2015 · 3 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@viesturz
Copy link

viesturz commented Jan 4, 2015

Hi,

I want to match multiple patterns with guards to a single code block.
I was wondering if there is any reason why the following code does not compile?

let b = (3i,4i);
let g = 0i;
match b {
   (2,_) | (_, 2) => println!("2 inside "), // this works fine
   (2,_) if g > 0 => println!("First is 2 and some guards"), // also works fine
   (2,_) if g > 0 | (_, 2) => println!("2 inside and some guards"), // this does not compile
   ....
}

Also have you considered allowing to use a general if condition syntax in matches, like this?

   ((2,_) && g > 0) || (_, 2) => 

Edit:

Also this does compile, but looks a bit ambiguous to what part of the pattern the guard applies to.

(2,_) | (_, 2) if g > 0 => println!("2 inside and some filters"),
@ftxqxd
Copy link
Contributor

ftxqxd commented Jan 4, 2015

See RFC #99, a postponed RFC that would add this feature among others.

@petrochenkov petrochenkov added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jan 19, 2018
@oberien
Copy link

oberien commented May 7, 2018

I just ran into the same issue. Is there any update on this?

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Closing in favor of #263.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants