Open
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();
}
Metadata
Metadata
Assignees
Labels
Relating to patterns and pattern matchingArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121Category: Discussion or questions that doesn't represent real issues.Nominated for discussion during a lang team meeting.Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.Relevant to the language team