@@ -110,17 +110,30 @@ match &mut v {
110
110
[ reference-level-explanation ] : #reference-level-explanation
111
111
112
112
` .. ` can be used as a pattern fragment for matching sub-slices and sub-arrays.
113
- It is treated as a "non-reference-pattern" for the purpose of determining default-binding-modes,
114
- and so shifts the binding mode to by-` ref ` or by-` ref mut ` when used to match a subsection of a
115
- reference or mutable reference to a slice or array.
113
+
114
+ The fragment's syntax is:
115
+ ```
116
+ SUBSLICE = .. | BINDING @ ..
117
+ BINDING = ref? mut? IDENT
118
+ ```
119
+
120
+ The subslice fragment incorporates into the full subslice syntax in the same way as the ` .. `
121
+ fragment incorporates into the stable tuple pattern syntax (with regards to allowed number of
122
+ subslices, trailing commas, etc).
116
123
117
124
` @ ` can be used to bind the result of ` .. ` to an identifier.
118
125
126
+ ` .. ` is treated as a "non-reference-pattern" for the purpose of determining default-binding-modes,
127
+ and so shifts the binding mode to by-` ref ` or by-` ref mut ` when used to match a subsection of a
128
+ reference or mutable reference to a slice or array.
129
+
119
130
When used to match against a non-reference slice (` [u8] ` ), ` x @ .. ` would attempt to bind
120
131
by-value, which would fail due a move from a non-copy type ` [u8] ` .
121
132
122
- ` .. ` / ` IDENT @ .. ` is not a full pattern syntax, but rather a part of slice, tuple and tuple
133
+ ` .. ` is not a full pattern syntax, but rather a part of slice, tuple and tuple
123
134
struct pattern syntaxes. In particular, ` .. ` is not accepted by the ` pat ` macro matcher.
135
+ ` BINDING @ .. ` is also not a full pattern syntax, but rather a part of slice pattern syntax, so
136
+ it is not accepted by the ` pat ` macro matcher either.
124
137
125
138
# Drawbacks
126
139
[ drawbacks ] : #drawbacks
@@ -209,8 +222,7 @@ range pattern, then it means that we consumed too much and need to reinterpret t
209
222
somehow. It's probably possible to make this work, but it's some headache that we would like to
210
223
avoid if possible.
211
224
212
- This RFC no longer includes the addition of ` ..PAT ` or ` PAT.. ` , but merely ` .. ` as it results in
213
- a smaller starting surface-area for the feature which can be expanded in the future if necessary.
225
+ This RFC no longer includes the addition of ` ..PAT ` or ` PAT.. ` .
214
226
The currently-proposed change is a minimal addition to patterns (` .. ` for slices) which
215
227
already exists in other forms (e.g. tuples) and generalizes well to pattern-matching out sub-tuples,
216
228
e.g. ` let (a, b @ .., c) = (1, 2, 3, 4); ` .
0 commit comments