Stabilize fixed-length slice patterns (excluding ..) (original) (raw)

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 ?)

Things not stabilized