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

Use pattern matching instead of checking lengths explicitly #85900

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

LingMan
Copy link
Contributor

@LingMan LingMan commented Jun 1, 2021

This piece of code checks that there are exaclty two variants, one having
exactly one field, the other having exactly zero fields. If any of these
conditions is violated, it returns None. Otherwise it assigns that one
field's ty to field_ty.

Instead of fiddling with indices and length checks explicitly, use pattern
matching to simplify this.

@rustbot modify labels +C-cleanup +T-compiler

@rustbot rustbot added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2021
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 1, 2021
@petrochenkov
Copy link
Contributor

r=me with nit addressed.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 1, 2021
This piece of code checks that there are exaclty two variants, one having
exactly one field, the other having exactly zero fields. If any of these
conditions is violated, it returns `None`. Otherwise it assigns that one
field's ty to `field_ty`.

Instead of fiddling with indices and length checks explicitly, use pattern
matching to simplify this.
@petrochenkov
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 1, 2021

📌 Commit e2b22b5 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 1, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2021
Rollup of 13 pull requests

Successful merges:

 - rust-lang#83362 (Stabilize `vecdeque_binary_search`)
 - rust-lang#85706 (Turn off frame pointer elimination on all Apple platforms. )
 - rust-lang#85724 (Fix issue 85435 by restricting Fake Read precision)
 - rust-lang#85852 (Clarify meaning of MachineApplicable suggestions.)
 - rust-lang#85877 (Intra doc link-ify a reference to a function)
 - rust-lang#85880 (convert assertion on rvalue::threadlocalref to delay bug)
 - rust-lang#85896 (Add test for forward declared const param defaults)
 - rust-lang#85897 (Update I-unsound label for triagebot)
 - rust-lang#85900 (Use pattern matching instead of checking lengths explicitly)
 - rust-lang#85911 (Avoid a clone of output_filenames.)
 - rust-lang#85926 (Update cargo)
 - rust-lang#85934 (Add `Ty::is_union` predicate)
 - rust-lang#85935 (Validate type of locals used as indices)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ad7b56e into rust-lang:master Jun 3, 2021
@rustbot rustbot added this to the 1.54.0 milestone Jun 3, 2021
@LingMan LingMan deleted the pat_mat branch June 3, 2021 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants