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

change "when" to "if" in pattern guards #1396

Closed
nikomatsakis opened this issue Dec 30, 2011 · 14 comments
Closed

change "when" to "if" in pattern guards #1396

nikomatsakis opened this issue Dec 30, 2011 · 14 comments
Labels
A-frontend Area: frontend (errors, parsing and HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@nikomatsakis
Copy link
Contributor

I suggest we replace the word "when" in pattern guards with the word "if". This is the only place that "when" appears in our grammar and so it would seem more consistent:

alt foo {
    pat(a, b) if cond { ... }
    pat(a, b) { ... }
}
@brson
Copy link
Contributor

brson commented Dec 31, 2011

I'm ok with this.

@kud1ing
Copy link

kud1ing commented Jan 6, 2012

Is it possible that for this one only needs to

  • adjust parse_alt_expr() in parser.rs
  • adjust print_expr() in pprust.rs
  • fix the using codes and tests

?

@nikomatsakis
Copy link
Contributor Author

Yes.

@brson
Copy link
Contributor

brson commented Jan 6, 2012

The parser will need to temporarily accept both 'when' and 'if', then we do a snapshot, then remove 'when'.

@brson
Copy link
Contributor

brson commented Jan 7, 2012

@Lenny222 are you working on this?

@kud1ing
Copy link

kud1ing commented Jan 8, 2012

@brson I considered it, but haven't started yet. Someone can go ahead if he wants to.

@thoughtpolice
Copy link
Contributor

I will implement this. I have most of the changes done but need to test it.

@thoughtpolice
Copy link
Contributor

@brson The above change makes the parser accept both when and if in alt patterns. It changes the pretty printer to unambiguously print if in alt patterns as well. I have run the entire test suite and it seems OK. Feel free to push to the try branch first.

I have the remaining changes to the code under src to change when -> if (which felt surprisingly small actually) but I cannot test them until a snapshot is created with this change. Does this commit look OK and if so, can you merge and snapshot? I will follow up with the 2 remaining commits (change usages throughout code, and remove 'when' from the parser) afterwords.

@brson
Copy link
Contributor

brson commented Jan 9, 2012

lgtm. I will let you know when the snapshot is done.

brson pushed a commit that referenced this issue Jan 9, 2012
Also fix the pretty printer, making it output 'if' instead of 'when'.

Issue #1396
@brson
Copy link
Contributor

brson commented Jan 9, 2012

We will also need to update the language docs and the tutorial

@thoughtpolice
Copy link
Contributor

OK. I will do that too and put the commits in this issue before I close it.

@brson
Copy link
Contributor

brson commented Jan 10, 2012

Snapshots are done.

@thoughtpolice
Copy link
Contributor

@brson The 3 commits mentioned above should take care of the rest of this issue. They replace all occurrences of when with if, remove parser support, and fix up the documentation and tutorial. I ran the testsuite (especially after removing parser support) and everything seems A-OK

I believe with all of that taken care of, once merged, that should close this issue.

Note: I re-pushed my issue-1396 branch after you merged my last change, so you may have to re-pull it if you had it pulled already.

brson pushed a commit that referenced this issue Jan 10, 2012
@brson brson closed this as completed in 55edb4a Jan 10, 2012
@brson
Copy link
Contributor

brson commented Jan 10, 2012

Thanks! Merged.

bjorn3 added a commit to bjorn3/rust that referenced this issue Oct 9, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: frontend (errors, parsing and HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants