Should a `[..]` slice pattern constitute a discriminant read
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
As an unresolved question in the discussion around #138961, it's unclear whether matching [..] against a slice should constitute a read of the length (which would behave like a discriminant read), or if it should behave like a wildcard pattern _.
This affects borrow checking and closure captures.
The behavior implemented for closure captures in #138961 is that [..] does not read the length. @Nadrieril suggests that it would be more consistent to perform the read regardless.
The purpose of this issue is to track the resolution of this spec question and subsequent implementation.
An example program affected by this would be:
fn main() {
let mut a: &mut [i32] = &mut [1, 2, 3];
let mut f = || {
// currently, this does not capture anything.
// a read of the length would cause a capture of `a`
let [..] = a;
};
a[0] += 1; // mutate `a`. this would not compile if a discriminant read were performed
f();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the discussion in #138961 and the example program in this issue; compare the existing closure-capture behavior with the borrow-checking implications of treating [..] as a length read or as a wildcard. Done means the specification question is resolved and the corresponding behavior is implemented consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100