New tracking issue: #62254
Old content
Tracking issue for rust-lang/rfcs#495
Breaking Changes
This RFC is a breaking change for most users of slice patterns. The main change is that slice patterns now have the type [_] instead of &[_].
For example, in the old semantics
fn slice_pat(x: &[u8]) {
// OLD!
match x {
[a, b..] => {}
}
}
the [a, b..] would have the type &[u8], a would have the type u8 and b the type &[u8].
With the new semantics, [a, b..] would have the type [u8] and b the type [u8] - which are the wrong types. To fix that, add a & before the slice and a ref before the tail as if you were matching a struct (of course, use ref mut if you want a mutable reference):
fn slice_pat(x: &[u8]) {
// NEW
match x {
&[a, ref b..] => {}
}
}
Concerns to be resolved before stabilization
History and status
New tracking issue: #62254
Old content
Tracking issue for rust-lang/rfcs#495
Breaking Changes
This RFC is a breaking change for most users of slice patterns. The main change is that slice patterns now have the type
[_]instead of&[_].For example, in the old semantics
the
[a, b..]would have the type&[u8],awould have the typeu8andbthe type&[u8].With the new semantics,
[a, b..]would have the type[u8]andbthe type[u8]- which are the wrong types. To fix that, add a&before the slice and arefbefore the tail as if you were matching a struct (of course, useref mutif you want a mutable reference):Concerns to be resolved before stabilization
History and status