-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingA-slice-patternsArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language team
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
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingA-slice-patternsArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language team