Open
Description
Hello, sometimes you want to work with intermediate variables with pattern matching, but when introducing @
bindings rust gives an error cannot borrow value as mutable more than once at a time value is mutably borrowed by 'a' here
. But the same code can be made working if just split it into 2 pattern matches.
struct A(B);
struct B(i32);
fn main() {
works(A(B(1)));
not_works(A(B(1)));
}
fn not_works(mut foo: A) {
if let A(a @ B(b)) = &mut foo {
*b += 1;
*a = B(8);
}
}
fn works(mut foo: A) {
if let A(a) = &mut foo {
if let B(b) = a {
*b += 1;
*a = B(8);
}
}
}
Metadata
Metadata
Assignees
Labels
Relating to patterns and pattern matchingCategory: Discussion or questions that doesn't represent real issues.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.