6
6
# Summary
7
7
[ summary ] : #summary
8
8
9
- Permit matching sub-slices and sub-arrays with the syntax ` .. ` .
9
+ Permit matching sub-slices and sub-arrays with the syntax ` .. ` .
10
10
Binding a variable to the expression matched by a subslice pattern can be done
11
- using the existing ` <IDENT> @ <PAT> ` syntax, for example:
11
+ using syntax ` <IDENT> @ .. ` similar to the existing ` <IDENT> @ <PAT> ` syntax, for example:
12
12
13
13
``` rust
14
14
// Binding a sub-array:
@@ -75,17 +75,20 @@ match v {
75
75
# Reference-level explanation
76
76
[ reference-level-explanation ] : #reference-level-explanation
77
77
78
- ` .. ` can be used as a pattern for matching sub-slices and sub-arrays.
78
+ ` .. ` can be used as a pattern fragment for matching sub-slices and sub-arrays.
79
79
It is treated as a "non-reference-pattern" for the purpose of determining default-binding-modes,
80
80
and so shifts the binding mode to by-` ref ` or by-` ref mut ` when used to match a subsection of a
81
81
reference or mutable reference to a slice or array.
82
82
83
- ` @ ` can be used to bind the result of a ` .. ` pattern to an identifier.
83
+ ` @ ` can be used to bind the result of ` .. ` to an identifier.
84
84
85
85
When used to match against a non-reference slice (` [u8] ` ), ` x @ .. ` would attempt to bind
86
86
by-value, which would fail in the case that users haven't enabled ` feature(unsized_locals) `
87
87
(since otherwise it's not possible to bind ` [u8] ` to a variable directly).
88
88
89
+ ` .. ` /` IDENT @ .. ` is not a full pattern syntax, but rather a part of slice, tuple and tuple
90
+ struct pattern syntaxes. In particular, ` .. ` is not accepted by the ` pat ` macro matcher.
91
+
89
92
# Drawbacks
90
93
[ drawbacks ] : #drawbacks
91
94
@@ -94,8 +97,6 @@ None known.
94
97
# Rationale and alternatives
95
98
[ alternatives ] : #alternatives
96
99
97
- The ` PAT.. ` alternative was discussed in the motivational part of the RFC.
98
-
99
100
More complex syntaxes derived from ` .. ` are possible, they use additional tokens to avoid the
100
101
ambiguity with ranges, for example
101
102
[ ` ..PAT.. ` ] ( https://github.com/rust-lang/rust/issues/23121#issuecomment-301485132 ) , or
@@ -198,3 +199,9 @@ syntactic choices are quite different from Rust's general style.
198
199
[ unresolved ] : #unresolved-questions
199
200
200
201
None known.
202
+
203
+ # Future possibilities
204
+ [ future-possibilities ] : #future-possibilities
205
+
206
+ Turn ` .. ` into a full pattern syntactically accepted in any pattern position,
207
+ (including ` pat ` matchers in macros), but rejected semantically outside of slice and tuple patterns.
0 commit comments