Closed
Description
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
- The syntax conflicts with exclusive range patterns.
- Matches on &mut[] move the .. match & don't consider disjointness #8636 Matches on &mut[] move the .. match & don't consider disjointness
- cannot move into irrefutable slice patterns with multiple elements #26736 cannot move into irrefutable slice patterns with multiple elements
- [MIR] double drop with slice patterns #34708 double drop with slice patterns
- Yet another bug with slice_patterns #26619 (Only E-needstest) Yet another bug with slice_patterns
- LLVM Assertion: Both operands to ICmp instruction are not of the same type! #23311 (Only E-needstest) LLVM Assertion: Both operands to ICmp instruction are not of the same type!
History and status
- Implemented in Implement RFC495 semantics for slice patterns #32202
- Still needs better integration with MIR borrowck to resolve soundness concerns, I believe
Metadata
Metadata
Assignees
Labels
Blocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCMedium priorityRelevant to the language team, which will review and decide on the PR/issue.