Repository navigation
Stabilize fixed-length slice patterns (excluding ..) #48836
Copy link
Copy link
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamfinal-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Description
This is a sub-issue of the larger tracking issue for slice patterns (#23121). It specifically tracks the plans to stabilize fixed-length slice patterns -- that is, excluding the .. operator (which is entangled with some syntactic questions). There is an implementation PR in #48516.
Summary
Using this feature, a pattern like [a, b, c] can be used to match against fixed-length arrays:
let arr = [1, 2, 3];
let [a, b, c] = arr; // where arr: [T;3]
let [a, ref b, c] = arr; // where arr: [T;3]One can also use such a pattern to match against slices:
let arr = &[1, 2];
match arr {
[a, b, c] => { /* this arm will not apply */ }
[a, b] => { /* this arm will */ }
_ => { /* this wildcard is required, since we don't know length statically */
}Notable points and tests
Here are some of the things I think we should be testing. I didn't have time to find if we have all these tests, perhaps someone can help (cc @petrochenkov, @mikhail-m1 ?)
- test showing irrefutable matches (
let [a, b] =) applied to fixed-length to move things out - test showing irrefutable matches (
let [a, b] =) applied to create reference - test showing attempt to move from a borrowed array or slice gives error
- move-out-of-slice1.rs sort of tests that, but for an oddly special case involving box patterns
- test that wildcard is required when matching slice with fixed-length arrays
match-vec-fixedtests that we get warnings for two slice patterns of same length- other cases?
Things not stabilized
- The main thing not stabilized is the ability to create a slice of unmatched items.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamfinal-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Activity
nikomatsakis commentedon Mar 8, 2018
@rfcbot fcp merge
I propose we merge the subset above. @petrochenkov has a PR here:
#48516
I'd like to see us document the tests better, but I think that we have them =)
rfcbot commentedon Mar 8, 2018
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed.
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
petrochenkov commentedon Mar 8, 2018
There are many tests testing slice patterns (at least 67 of them contain
feature(slice_patters)), it's hard to find specific examples.compile-fail/borrowckcontains tests for moving out elements in array patterns erroneously.match-vec-*/match-slice-*tests incompile-failtest various pattern properties like exhaustiveness and number of elements.#47926 added tests for legally moving out elements from fixed-size arrays and dynamic drops.
irrefutable-slice-patterns.rscreates references with irrefutable slice patterns.rfcbot commentedon Mar 8, 2018
🔔 This is now entering its final comment period, as per the review above. 🔔
nikomatsakis commentedon Mar 9, 2018
@petrochenkov good enough, thanks
rfcbot commentedon Mar 18, 2018
The final comment period is now complete.
Auto merge of #48516 - petrochenkov:stabsl, r=nikomatsakis
Rollup merge of rust-lang#67712 - Centril:stabilize-slice_patterns, r…
Rollup merge of rust-lang#67712 - Centril:stabilize-slice_patterns, r…